Python类的继承顺序__mro__

class A:
    def test(self):
        print('print from A')
    pass

class B(A):
    # def test(self):
    #     print('print from B')
    pass

class C(A):
    def test(self):
        print('print from C')
    pass

class D(B):
    # def test(self):
    #     print('print from D')
    pass

class E(C):
    # def test(self):
    #     print('print from E')
    pass

class F(D,E):
    # def test(self):
    #     print('print from F')
    pass

f=F()
print(F.__mro__)
f.test()
输出:
class A:
    def test(self):
        print('print from A')
    pass

class B(A):
    # def test(self):
    #     print('print from B')
    pass

class C(A):
    def test(self):
        print('print from C')
    pass

class D(B):
    # def test(self):
    #     print('print from D')
    pass

class E(C):
    # def test(self):
    #     print('print from E')
    pass

class F(D,E):
    # def test(self):
    #     print('print from F')
    pass

f=F()
print(F.__mro__)
f.test()
posted @ 2021-05-13 15:06  ty1539  阅读(61)  评论(0编辑  收藏  举报