比如举个例子:
1 class A: 2 def __init__(self): 3 print("Enter A") 4 print("Leave A") 5 6 class B(A): 7 def __init__(self): 8 print("Enter B") 9 super(B, self).__init__() 10 print("Leave B") 11 12 class C(A): 13 def __init__(self): 14 print("Enter C") 15 super(C, self).__init__() 16 print("Leave C") 17 18 class D(A): 19 def __init__(self): 20 print("Enter D") 21 super(D, self).__init__() 22 print("Leave D") 23 24 class E(B, C, D): 25 def __init__(self): 26 print("Enter E") 27 super(E, self).__init__() 28 print("Leave E") 29 30 E()
运行结果是:
Enter E
Enter B
Enter C
Enter D
Enter A
Lever A
Lever D
Lever C
Lever B
Lever E
运行方式 从左向右,自底向上