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
上一篇: 数学题-计算相交圆的公共部分面积