欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python3中类继承采用广度优先

程序员文章站 2022-05-21 16:24:50
...

在python3中类的继承采用广度优先

# 在python3中类的继承采用广度优先
class A():
    def run(self):
        print('A')

class B(A):
    def run(self):
        super().run()
        print('B')

class C(A):
    def run(self):
        super().run()
        print('C')

class D(B,C):
    def run(self):
        super().run()
        print('D')

if __name__ == '__main__':
    d = D()
    d.run()
    print(D.__mro__)
A
C
B
D
(<class '__main__.D'>, <class '__main__.B'>, <class '__main__.C'>, <class '__main__.A'>, <class 'object'>)

Process finished with exit code 0

相关标签: Python