目录
什么是变量:
-
变:现实世界中的状态是会发生改变的。
-
量:记录现实世界中的状态,让计算机能够像人一样去识别世间万物
-
是变化的量
变量的组成:
-
变量名:变量名用来引用变量值,但凡需要用变量值,都需要通过变量名。
-
赋值符号:赋值
-
变量值:存放数据,用来记录现实世界中的某种状态
age = 18 height = 185 print(age) print(height)
-
变量的风格:
1.驼峰提:
AgeOfNick = 19
print(AgeOfNick)
2.下划线:
age_of_nick = 19
print(age_of_nick)
变量名的命名规范
-
变量的命名应该能反映变量值所描述的状态(切记不可用中文)
-
变量名必须用字母数字下划线组合,并且变量名的第一个字符不能是数字。
-
关键字不能声明为变量名
['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']