1 class A(object): 2 x = 1 3 4 class B(A): 5 pass 6 7 class C(A): 8 pass 9 10 # 通过父类修改类属性,子类继承的类属性也改变 11 A.x = 3 12 print(A.x, B.x, C.x) 13 # 通过子类修改继承自父类的类属性,只会改变该子类继承的类属性 14 B.x = 2 15 print(A.x, B.x, C.x) 16 # 子类先修改继承的类属性,父类再修改类属性,将不会再对已经修改过的子类类属性做出改变 17 B.x = 4 18 A.x = 1 19 print(A.x, B.x, C.x)