python basis
1. Variables
First, what is variable
Varying amounts, typically used to assign several values
Second, the definition of variables
Now that you know what the hell is variable, how do we define a variable in Python it?
name = 'nick'
age = 19
gender = 'male'
height = 180
weight = 140
Third, the compositional variables
Variable by the variable name (variable reception value) = (assignment symbol), the value of the variable (value) Composition
- Variable name : variable name used to refer to variable values, whenever required by the variable value goes through the variable name.
- Assignment symbol : Assignment
- Variable value : storing data used to record a certain state in the real world.
Fourth, the variable of Use
Use variable names in addition to the following, the principle can easily named, but we must remember that the definition of a variable is the state of the real world record, and deposit is not an end, the purpose is to take, so the best he can see the name You have to understand to refer to variables.
So named variables should meet the following three specifications:
- Named variables should reflect the values of the state variables as described, remember not to use Chinese
- Variable names must be a combination of alphanumeric characters and underscores, and the first character of the variable name can not be a number.
- Keywords 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']
- Keywords 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']
Six, two styles of variable names
6.1 hump body
AgeOfNick = 19
print(AgeOfNick)
6.2 Underline (recommended)
ge_of_nick = 19
print(age_of_nick)
Note: The style of two or more variable names, it is recommended to use the underline style.