Day29.非菱形继承下属性的查找顺序
1.非菱形继承下属性的查找顺序_python3下.mro()的查找顺序
''' 如果多继承是非菱形继承,python2和python3的属性查找顺序一样: 都是一个分支一个分支的找下去,然后最后找object ''' class E: # def test(self): # print('from E') pass class F: def test(self): print('from F') class B(E): # def test(self): # print('from B') pass class C(F): # def test(self): # print('from C') pass class D: def test(self): print('from D') class A(B, C, D): # def test(self): # print('from A') pass print('.mro()查看函数顺序'.center(40, '-')) print(A.mro()) # 顺序: A->B->E->C->F->D->object obj = A() obj.test()