class Bus():
lock = (1,‘222‘,222)
def show(self):
print(id(self.lock))
a = Bus()
b = Bus()
c = Bus()
a.show()
b.show()
c.show()
# 排除小整数池的影响
a = (1,‘222‘,222)
b = (1,‘222‘,222)
print(id(a))
print(id(b))
结果:
1854485426968
1854485426968
1854485426968
1854485426752
1854485473392
所以,类属性的地址是一样的。跟闭包有点像。
原文:https://www.cnblogs.com/pythonwl/p/14251829.html