python acquaintance of variables

python variables

    What is variable

# Amount of the variable that is changed, the core is "change" and "quantity" word, change that is a change, that is a measure of the amount of state.

    Why should there be variable

# Nature of the program execution is a series of changes in state, change is directly reflected in the implementation of the program, so we need to have a mechanism to reflect changes in or is saved when the program execution state and state.
# For example:  the hero is rated 1, Daguai upgrade (change) of 10 Zombie survival state True, the plant is killed, then becomes False Person's name is kermit, it can also be modified to Kermit 

    How to define the variable (illustration)

# Variable name (the equivalent of house number, pointed to the space where the value), equal sign, variable values
name='Kermit' sex='male' age=18 level=10

    Specification defined variables

# 1. Variable names can be any combination of letters, numbers, or underscores the 
# first character 2. The variable name not a number  # 3. The keyword can not be declared as a variable name [ '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 ']

    Defined method:

Copy the code
# Hump body
AgeOfOldboy = 56 
NumberOfStudents = 80
# Underscore (recommended)
age_of_oldboy = 56 number_of_students = 80
Copy the code

     Defined variable names a bad way

# 1. variable named Chinese, Pinyin 
# 2. The variable name is too long  # 3 variables do not convey term

    Define the variable will be: id, type, value

Copy the code
Copy the code
# 1 is relatively equal sign value, 
# 2 IS comparison is id

# Stressed: # identical 1. id, meaning and value must be the same type # 2. value the same type is certainly the same, but id may be different, as the X-= >>> ' Info Kermit: 18 ' the y->>> = ' Info Kermit : 18 is ' >>> ID (X) 4376607152 >>> ID (Y) 4376607408 >>> >>> X == Y >>> True X IS Y False
Copy the code
Copy the code
Small integer pool

 

 

Guess you like

Origin www.cnblogs.com/lweiser/p/lweiser.html