python basis
variable
Defined : variables used to describe the state of things in the world change
Composition :
Variable name: receiving variable values
Assignment symbol: the variable value is assigned to the variable name
Variable Value: is a value
Note :
- Variable names by the number / letter / underscore, can not start with a number
- Variable names can not be named the following keywords
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']
- Variable names have meaning, do not use Chinese,
The definition of a variable name two styles:
Hump body:AgeOfNick
(capitalize the first letter of each word)
Underline : age_of_nick
(each word in connection with an underscore)
constant
Defined : the same amount (in constant variable in python, but try not to change, it is conventional immutable)
Composition : the all uppercase English letters
python variable memory management
The new definition of a variable, just open up a new memory space
Not necessarily the same variable values are the same id, id the same variable values necessarily the same.
Reference count
Variable n has a variable name value points A, then A reference count is n.
Garbage collection
When the reference variable value of the count is 0, python parser automatically releases the memory variable.
Small integer pool
An integer between [-5,256] when the python interpreter starts automatically generated, so it will not be garbage recycling system.
Three features of the definition of a variable name
Print variable name
Print variable memory address
Print variable data types
Fancy assignment
Chain assignment :
x=y=z=10
Cross assignment :
x = 20
y = 10
x, y = y, x
z = x
x = y
y = z
Note
Single-line comments
# 单行注释
ctrl + /
Multi-line comments
'''
多行注释
多行注释
'''
"""
多行注释
多行注释
"""