变量内存地址与值

#一:变量名的命名的大前提:应该能够反映出变量值所记录的状态
# 具体的,变量名的命名规范如下:
# 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']
# print=18
# print()

# 二:变量名的命名风格
# 2.1 驼峰体
# AgeOfOldboy=73

# 2.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)
# 2160909722736
# >>> id(n)
# 2160909725424
# >>> m is n
# False

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

# m = 100
# n=100
#
# print(id(m))
# print(id(n))
# 输出结果如下
# 1452898880
# 1452898880
#
# print(m is n)

 

posted on 2018-12-28 17:06  小胖子方法  阅读(163)  评论(0编辑  收藏  举报

导航