mro order of succession and inheritance diamond (diamond inheritance)

1. Call mro returns a succession sequence, the order of succession super strictly follow the sequence inherited mro

Cause under diamond inheritance multiple inheritance cases: 2. Diamond inheritance

  Those who inherit the object class of the object is new-style class, python3 default all classes are inherited object class, are the new class

  python2 There are new classes and class inheritance object is the classic Classic

  Find mro order: new categories: breadth-first Classic: depth-first

 Multiple inheritance: the inheritance order from left to right by default

# 新式类:
class A(object):
    # def test(self):
    #     print('from A')
    pass

class B(A):
    # def test(self):
    #     print('from B')
    pass

class C(A):
    # def test(self):
    #     print('from C')
    pass
class D(B):
    # def test(self):
    #     print('from D')
    pass

class E(C):
    # def test(self):
    #     print('from E')
    pass

class F(D, E):
    # def test(self):
    #     print('from F')
    pass

# F-->D-->B-->E-->C-->A-->object
# print(F.mro())
obj = F()

 

Guess you like

Origin www.cnblogs.com/bigbox/p/11939043.html