python MRO在继承中的使用

class Parent:
    x=1

class Child1(Parent):
    pass

class Child2(Parent):
    pass

print(Parent.x,Child1.x,Child2.x)

Child1.x=2
print(Parent.x,Child1.x,Child2.x)

Parent.x=3
print(Parent.x,Child1.x,Child2.x)

结果: 

猜你喜欢

转载自blog.csdn.net/dxm809/article/details/107294543