1. 程式人生 > >新式類多繼承的查找順序

新式類多繼承的查找順序

brush 方法 main img pass true div inf http

新式類的多繼承遵循C3算法

class X:
    pass
class S(X):
    pass
class A(X):
    pass
class B(S):
    pass
class C(A):
    pass
class D(B):
    pass
class E(C):
    pass
class F(D, E, B):
    pass
f1 = F()

print(F.mro())
# [<class ‘__main__.F‘>, <class ‘__main__.D‘>, <class ‘__main__.E‘>, <class ‘__main__.B‘>, <class ‘__main__.C‘>, <class ‘__main__.A‘>, <class ‘object‘>]

# 新式類多繼承

  方法:

技術分享圖片

新式類多繼承的查找順序