Variables: define the state of things in the world change
'''
height 180
weight 140
age 18
tree_name yuyang
'''
print(180)
height = 180
print('height:', height)
weight = 140
print('weight:', weight)
age = 18
print('age:', age)
tree_name = 'yuyang'
print('tree_name:', tree_name)
Compositional variables (in line with the variable name composed pretty good)
Variable name (described; receiving variable values) of assignments (assignments, the value of the variable pass variable names) values (specific values)
Specification of variable names
akljfdksl = 10
print('akljfdksl:', akljfdksl)
1. Variable names must be descriptive sense
2. The variable name from the number / letter / underscores, and can not begin with a number
$ = 10
print($)
10tree = 10
print(10tree)
3. Keyword can not be named
'''
['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']
'''
Two ways to define the variable (code top-down operation, if the same variable name is executed later)
Underline the word is generally used to connect
name_of_nick = 'nick' # underline style (recommended, must)
NameOfJason = 'jason' # hump body
print (name_of_nick) # define to use, without the quotation marks is the variable name
Constant: quantity does not change (the variable name all uppercase)
age = 1
age = age + 1
print(age)
Constant: change is not prescriptive
AGE = 1
AGE = AGE + 1 # before doing stupid Cock
Constant: the agreement does not change commonly known, can actually change, but when you are forced to change, you get out the next day
python Memory Management
Variable concept python interpreter is provided, when only run python
Definition of variables and run to open up a new memory space to store variable
Reference count (for variable value): value of the variable reference number
age = 1000 # 1000 reference count of 1
age1 = age # 1000 reference count of 2
del age # delete delete age, a reference count of 1 1000
print(age1)
Del age1 # 1000 reference count of 0
Garbage collection mechanism: When the value of a variable reference count is 0, it will trigger a garbage collection mechanism, the magnitude of change will be recycled
# id
age = 1000
print (age) # print value
print (id (age)) # memory address of the variable value of 1,507,487,488
# Small integers pool
age1 = age
print(id(age1))
# When python boot, will automatically define an integer variable between [-5,256], their memory has been written is dead
age = 10
age1 = age
del age
the age1
Logically speaking, because of the trigger garbage collection, but because 10 is a small integer pool, does not trigger garbage collection
When the interview you may ask, can this test to your level --- "gil Global Interpreter Lock
Variable names for receiving variable values
Define the variable memory space will open up new
PyCharm own optimized (fast frequency short), pycharm the small integer range expanded pool
Print value
print(age)
Print memory address
print(id(age))
Type of print data ()
print(type(age))