周一03.1变量补充

一、变量名的命名的大前提:应该能够反映出变量值所记录的状态
具体的,变量名的命名规范如下:
1、变量名是由字母、数字、下划线组成
2、不能以数字开头
3、不能使用关键字命名变量名
['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']

二、变量名的命名风格
1、驼峰体
AgeOfOldboy=73

2、纯小写+下划线(推荐使用该方式)
age_of_oldboy=73

三、变量值具备三大特征
age=18
id:是通过内存地址计算而来,id如果不同内存地址肯定不同 //print(id(age))
type //print(type(age))
值 //print(age)

is:判断的是id是否相等
==:判断的是值是否相等

id不同,值有可能相同
>>> m=123456
>>> n=123456
>>> m==n
True
>>> id(m)
3908720
>>> id(n)
3911408
>>> m is n
False

id相同,值一定相同
>>> x=123456
>>> y=x
>>> id(x)
34503472
>>> id(y)
34503472
>>> x is y
True
>>> x==y
True


常量
AGE_OF_OLDBOY=73
AGE_OF_OLDBOY=74
print(AGE_OF_OLDBOY)

原文地址:https://www.cnblogs.com/wanglimei/p/10190531.html