Variable, the interpreter, garbage collection, small integer value summary

python interpreter role

After writing python code is stored, we will get a .py extension to a text file. To do this, run the file you need python interpreter.

Two ways to run the python program

Interactive mode

In Python interactive environment, you can only enter Python code and execute immediately.

Command line mode

Command line mode is executed .py text files.

Note

What is a comment?

Notes that the code of explanatory notes, comments will not be content as the code runs.

Why should we comment?

Enhance the readability of the code

How to use annotations?

Single-line and multi-line comments

1. Single-line comments using a #, the code may be followed immediately above or immediately behind

2. Multi-line comments may be three pairs or three pairs of double quotes single quotes

What is IDE? Why should IDE?

That IDE integrated development environment. The best Python IDE tool is pyCharm

IDE is a function of n software can inherit, but there is code hinting and error correction function, can greatly improve development efficiency.

variable

What is a variable? Why should there be variable? How to use variables?

Variable is the amount may vary

In order to let the computer like people to remember things in a certain state, and the state changes can occur.

These three parts are variable names assigned symbol value of the variable a = 1 Example

Naming the variable name

1. Variable names can only be a combination of letters, numbers, or underscore

2. The first character variable names can not be digital

3. Keywords can not be defined as a variable

4. You can not use Chinese when the variable name (although they would succeed, but the very suggestion, too low a)

Only if it meets all the above conditions can be successfully defined variable names

Variable naming style

1. hump body

Capitalize the first letter of each word such as: Name_Age = 18

2. underscore body

Between each word, for example, underlined: Name_Age = 18

constant

What is constant? Why should there be constant? How to use constants?

Constant is the amount in the program is running will not change

Some values ​​in the program execution is fixed, and should not be changed.

python this argument is not constant, but programmers convention with all uppercase words as constants. So variables and constants are the same, but the best Do not attempt to change the constants.

Small integer pool

In order to optimize the speed of Python, using a small integer object pooling, avoiding the frequent application is an integer and destruction of memory space. Python definition of small integers is [-5, 256] These objects are integer-established in advance and will not be garbage collected. In a Python program, no matter in which position LEGB integer in, repeat all the variables defined in the same object integer between -5 to 256, the values ​​of these variables are used.

Garbage collection

Reference count the number of times the associated variable value variable name

Clear labeling for solving the problem of circular references when the application is run out of available space will stop the entire program labeled Clear

Generational recovery in order to avoid repeated scans the reference count, then the case of multiple variable experienced scans have not been recovered, the scanning frequency will be reduced.

 

Guess you like

Origin www.cnblogs.com/chenyangdada/p/11779550.html