class Parent(object) x = 1 class Child1(Parent): pass class Child2(Parent): pass print Parent.x, Childx, Childx Childx = 2 print parent.x, Childx, Childx parent.x = 3 print Parent.x, Childx, Childx
1 1 1 #继承自父类的类属性 x,所以都一样,指向同一块内存地址。 1 2 1 #更改 Child1,Child1 的 x 指向了新的内存地址。 3 2 3 #更改 Parent,Parent 的 x 指向了新的内存地址。