python的变量统统是引用型的。请看下面的代码并思考:
a=4
print(id(a)) #取a地址并打印
print(id(4))
print(id(6))
a = a+1
print(id(a)) # 对a+1求值并重新创建一个对象
a="hello"
print(id(a)) # python的变量统统是引用型的,上述4,a+1,"hello"统统是新建立的对象,而a=对象是调用对应的引用
输出:
140714475217648
140714475217648
140714475217712
140714475217680
2695807314832