class A(object):
def foo(self):
print('A foo')
def bar(self):
print('A bar')
class B(object):
def foo(self):
print('B foo')
def bar(self):
print('B bar')
class C1(A):
pass
class C2(B):
def bar(self):
print('C2-bar')
class D(C1,C2):
pass
if __name__ == '__main__':
print(D.__mro__)
d=D()
d.foo()
d.bar()
为什么最后的结果是
(<class '__main__.D'>, <class '__main__.C1'>, <class '__main__.A'>, <class '__main__.C2'>, <class '__main__.B'>, <class 'object'>)
A foo
A bar
而不是
(<class '__main__.D'>, <class '__main__.C1'>, <class '__main__.A'>, <class '__main__.C2'>, <class '__main__.B'>, <class 'object'>)
A foo
A bar
B foo
B bar
LZJ在课上
相关分类