面向对象的多继承
先找左 ,再找右
class A(object): pass class B(object): def f1(self): print('B') class C(A,B): pass obj = C() obj.f1()
经典类
新式类
经典类和新式类的查找成员的顺序不一样。
经典类,一条道走到黑(深度优先)。
新式类,C3算法实现
class A(object): pass class B(A): pass class C(B): pass class D(object): pass class E(D,C): pass class F(object): pass class G(F): pass class H(C,G): pass class Foo(E,H): pass # print(E.__mro__) # print(H.__mro__) """ L(Foo + L(E) + L(H) ) L(E) = E,D,C,B,A,object L(H) = H,C,B,A,G,F,object Foo = (object) + (G,F,object) Foo,E,D,H,C,B,A,G,F,object """ print(Foo.__mro__)