1 #!/user/bin/env python 2 # -*- coding:utf-8 -*- 3 4 5 class A: 6 def __init__(self): 7 print('A') 8 9 10 class B(A): 11 def __init__(self): 12 print('B') 13 super().__init__() 14 15 16 class C(A): 17 def __init__(self): 18 print('C') 19 super().__init__() 20 21 22 class D(B, C): 23 def __init__(self): 24 print('D') 25 super().__init__() 26 27 28 if __name__ == '__main__': 29 print(D.__mro__) 30 d = D()
(<class '__main__.D'>, <class '__main__.B'>, <class '__main__.C'>, <class '__main__.A'>, <class 'object'>)
D
B
C
A
super其实是根据mro算法来调用的