First time learning Python

Basic components and functions of a computer

The basic components of a computer are: CPU; memory; hard disk; operation center.

CPU:

  The central processing unit, equivalent to the brain of the computer, the computing center, the processing of data and the operation of various instructions all need to go through the CPU.

RAM:

  Temporarily store a small amount of data for the CPU to perform operations.

    Pros: Fast read speed.

    Disadvantages: small capacity; high cost; data can only be temporarily stored, and the data will disappear after power failure.

hard disk:

  Store a large amount of data for a long time, the power will not disappear, and the data stored in the computer for a long time is on the hard disk.

    Advantages: large capacity; low cost; power failure data will not disappear.

    Disadvantage: slow read speed.

For operating system:

  Coordinate operations between hardware.

  Common operating systems are: windows; linux; cenos, mac.....

First acquaintance with Python

History of Python Development (Citation 1)

The history of python

1. The founder of python is Guido van Rossum. During Christmas in 1989, Guido Van Rossum (Chinese name: Uncle Gui) decided to develop a new script interpreter as a successor to the ABC language in order to pass the time in Amsterdam.  

(Uncle Turtle: joined Google in 2005 to 2012, joined Dropbox in 2013, and still holds the core direction of Python development, known as a benevolent dictator ). (Because of the switching problem between python2x and python3x, the buffer time is given)

2. At present, the main application areas of Python are:

  • Cloud computing : the most popular language for cloud computing, typical application OpenStack
  • WEB development: Many excellent WEB frameworks, many large websites are developed in Python, Youtube, Dropbox, Douban. . . , the typical WEB framework is Django
  • Scientific computing, artificial intelligence : typical libraries NumPy, SciPy, Matplotlib, Enthought libraries, pandas
  • System operation and maintenance : a necessary language for operation and maintenance personnel
  • Finance: Quantitative trading, financial analysis, in the field of financial engineering, Python is not only used, but also the most used, and its importance is increasing year by year. Reason: As a dynamic language, Python has a clear and simple language structure, rich libraries, mature and stable, scientific computing and statistical analysis are very powerful, production efficiency is much higher than c, c++, java, especially good at strategy backtesting
  • Graphical GUI: PyQT, WxPython, TkInter

2. History of python development

( 1) History

  • In 1989, in order to pass the Christmas holidays, Guido started writing a compiler for the Python language. The name Python comes from Guido's beloved TV series, Monty Python's Flying Circus. He hoped that the new language, called Python, would meet his vision: to create a full-featured, easy-to-learn, and extensible language between C and the shell.
  • In 1991, the first Python compiler was born. It is implemented in C language and can call C language library files. From birth, Python has had: classes, functions, exception handling, core data types including tables and dictionaries, and a module-based extension system.
  • Granddaddy of Python web frameworks, Zope 1 was released in 1999
  • Python 1.0 - January 1994 added  lambdamapfilter  and  reduce .
  • Python 2.0 - October 16, 2000, added a memory recycling mechanism, which forms the basis of the current Python language framework
  • Python 2.4 - November 30, 2004, the same year the most popular WEB framework Django was born
  • Python 2.5 - September 19, 2006
  • Python 2.6 - October 1, 2008
  • Python 2.7 - July 3, 2010
  • In November 2014, it was announced that Python 2.7 would be supported until 2020, and reaffirmed that there would be no 2.8 release as users were expected to move to Python 3.4+ as soon as possible 2.7 until 2020 , and reiterates that there will not be a 2.8 version as users will likely migrate to Python 3.4+ soon . )
  • Python 3.0 - December 3, 2008
  • Python 3.1 - June 27, 2009
  • Python 3.2 - February 20, 2011
  • Python 3.3 - September 29, 2012
  • Python 3.4 - March 16, 2014
  • Python 3.5 - September 13, 2015
  • Python 3.6 - December 16,2016

( python2.6 and python3.0 are updated in the same year, python2x is updated to 2020, and the updated modes and specifications are gradually approaching python3x)

( 2) Difference between python2x and 3x

 Python: beautiful, clear, simple.

Python2x: The source code is not standardized, messy, and there are many repeated codes. Default encoding ascii

    Display Chinese: first line: # -*- encoding:utf-8 -*-

Python3x: Reorganized source code, source code specification, beautiful, clear and simple. The default encoding is utf-8.

 

Classification of python

1. Overall language classification:

Classification:

1. Compiled

  Compile the code all at once to secondary and then run it.

  Advantages: high execution efficiency.

  Disadvantages: slow development efficiency, not cross-platform.

  Representative language: C.

2. Interpretive

  The code is interpreted line by line, interpreted into binary, and then run.

  Advantages: high development efficiency, third-party library, cross-platform.

  Disadvantages: low execution efficiency.

  Representative language: Python.

2. Various types of language representatives:

 Compiled: C; c++; Go; Swift; Object-C; Pascal.

 Interpreted: JavaScript; Python; Ruby; PHP; Perl; Erlang.

Hybrid: JAVA; C#.

Advantages and disadvantages of python

 

advantage

1. The positioning of Python is "elegant", "clear", and "simple", so Python programs always look simple and easy to understand . Beginners learn Python, not only is it easy to get started, but also in the future, you can write those very, very complex program.

2. The development efficiency is very high . Python has a very powerful third-party library. Basically, you want to realize any function through the computer. There are corresponding modules in the official Python library to support it. Carry out development, greatly reduce the development cycle, and avoid duplication of wheels.

3. High-level language - When you write programs in Python, you don't need to think about low-level details such as how to manage the memory used by your program (memory usage is efficient, and the memory footprint is small)

4. Portability - Due to its open source nature, Python has been ported to many platforms (modified to work on different platforms). If you are careful to avoid using system-dependent features, then all your Python programs will run without modification on almost every system platform on the market

5. Scalability - If you need a critical piece of your code to run faster or want some algorithms to be private, you can write part of your program in C or C++ and use it in your Python program they.

6. Embeddability - You can embed Python into your C/C++ programs to provide scripting capabilities to your program users.

shortcoming:

1. The speed is slow . The running speed of Python is indeed much slower than that of the C language, and it is also slower than that of JAVA, so this is also the main reason why many so-called big cows disdain to use Python, but in fact the running speed referred to here is In most cases, users cannot directly perceive the slowness, and it must be reflected by testing tools. For example, if you use C to run a program, it takes 0.01s, and it takes 0.1s to use Python. In this way, C language is directly 10 times faster than Python. , It is very exaggerated, but you cannot directly perceive it through the naked eye, because the smallest unit of time that a normal person can perceive is about 0.15-0.4s, haha. In fact, in most cases, Python can fully meet your program speed requirements, unless you want to write a search engine that requires extremely high speed. In this case, of course, it is recommended that you use C to achieve it.

2. The code cannot be encrypted , because PYTHON is an interpretive language, and its source code is stored in the form of name text, but I don't think this is a disadvantage. If your project requires the source code to be encrypted, then you start It should not be implemented in Python.

3. Threads cannot use multiple CPUs , which is one of the most criticized shortcomings of Python. GIL, or Global Interpreter Lock, is a tool used by computer programming language interpreters to synchronize threads . There is a thread executing, and Python's thread is the native thread of the operating system. A pthread on Linux and a Win thread on Windows, the execution of the thread is entirely scheduled by the operating system. A python interpreter process has one main thread and multiple execution threads of user programs. Even on multi-core CPU platforms, parallel execution of multiple threads is prohibited due to the presence of the GIL. A compromise solution to this problem will be discussed in detail later in the Threads and Processes chapter.

When we write Python code, what we get is a text file with a .py extension containing the Python code . To run the code, the Python interpreter is required to execute the .py file.

Since the entire Python language is open source from the specification to the interpreter, theoretically, as long as the level is high enough, anyone can write a Python interpreter to execute Python code (of course, it is very difficult). In fact, multiple Python interpreters do exist.

 

variable 

Variable: The intermediate result of the calculation is stored for subsequent code use.

Rules for variable setting:

  1. Must be any combination of letters, numbers, and underscores.

  2. It cannot start with a number.

  3. Cannot be a keyword in Python.

  4. The variable cannot be in Chinese,

  5. Variables cannot be too long.

  6. Variables are descriptive.

 

constant

Constant: A quantity that never changes. Variables that default to all uppercase are constants.

Notes

Helps you understand other people's code and recall your own code.

Single-line comment: #The commented content; multi-line comment'''remark is content''' """remark is content"""

 Boolean (logical judgment)

Boolean value (bool) has only two values ​​True (true) False (false), mainly used for logical judgment.

Boolean values ​​are all capitalized.

type (data attribute judgment)

Determine what data type the object belongs to

name = input('Please enter your name:') 
age = input('Please enter your age:')
print(name,age,type(name),type(age))

input (content interaction)

Input is the most basic content interaction. It is mainly used to let the user input mainly, and the input object is a string.

 

name = input('Please enter your name:') 
age = input('Please enter your age:')
print(name,age,type(name),type(age))

if (if)

1. Single write:

if space condition: (colon)

(four spaces ( tab)) result

That is: if XXXX

then xxxx

print(111)
if 3 > 2:
print(666)
print(333)
2.if with else (if... else...)
if else
name = input('Please enter your name:')
if name == 'Your Highness':
print('Old iron, no problem')
else:
print('Ill be cured....')
3.if with elif (if...or...or...)

if elif...
num = int(input('Please enter your choice:')) # str ---> int str is all composed of numbers 
if num == 4:
print('I'll have lunch')
elif num == 5:
print ('Dinner, please')
elif num == 6:
print('Health care, let's go')
3.if with elif...else (if...or...otherwise...)
if elif ... else

num = int(input('Please enter your choice: ')) # str ---> int str is all composed of numbers
if num == 4:
print('I'll have lunch')
elif num == 5:
print('Dinner, please')
elif num == 6:
print('Health care, let's go')
else:
print('Give you a chance to miss....')


Nested
Ask many times, according to the rules read by python, from top to bottom, the question leads to the question, and finally the answer is obtained, but the unfinished instruction above will go directly to the result.
num1 = input('Please enter the number') 
if num1 == '3':
num2 = input('Please enter the number:')
if num2 == '5':
print('It can all be guessed correctly')
else:
print ('Keep working hard')

score = int(input("input score:"))
if score > 100:
print("I wipe, the highest score is 100...")
elif score >= 80:
print("B" )
elif score >= 90:
print("A")
elif score >= 60:
print("C")
elif score >= 40:
print("D")
else:
print("Too stupid...E" )

 

while Condition: 
The result is
asked multiple times. According to the rules read by python, from top to bottom, the question leads to the question, and finally the answer is obtained, but the unfinished instruction above is directly transferred to the result.

 

 

Note the vocabulary :

while (loop) break (terminate loop) continue (terminate this loop)
print (print) True (true) False (false) if (if, suppose) else (else)
elif (or) input (output-dialogue) %sd (format) type (test nature)

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325169493&siteId=291194637