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): passclass C2(B): def bar(self): print('C2-bar')class D(C1,C2): passif __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 fooA bar而不是(<class '__main__.D'>, <class '__main__.C1'>, <class '__main__.A'>, <class '__main__.C2'>, <class '__main__.B'>, <class 'object'>)A fooA barB fooB bar
添加回答
举报
0/150
提交
取消