首页 > 编程语言 > 详细

Python类的继承顺序__mro__

时间:2021-05-13 20:29:11      阅读:30      评论:0      收藏:0      [点我收藏+]
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()

Python类的继承顺序__mro__

原文:https://www.cnblogs.com/heris/p/14764627.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!