Python编程整理:通过修改实例类变量改变类的类变量的问题(成因:类变量为可变变量)
先上代码,
class C1(object): class_variable = 1 class C2(object): class_variable = [] object1 = C1() object2 = C2() print(C1.class_variable) # 1 print(object1.class_variable) # 1 object1.class_variable = 20 print(object1.class_variable) print(C1.class_variable) # 20 # 1