python 2 和 python 3 代码均为:
1 #_*_coding:utf-8_*_ 2 #__author__ = "csy" 3 4 class A: 5 def __init__(self): 6 print("A") 7 8 class B(A): 9 pass 10 #def __init__(self): 11 # print("B") 12 13 class C(A): 14 def __init__(self): 15 print("C") 16 17 class D(B,C): 18 pass 19 #def __init__(self): 20 # print("D") 21 22 d1 = D()
python 2 显示A,python 3显示C
python 2的继承顺序是D -> B -> A -> C 深度优先
python 3的继承顺序是D -> B -> C -> A 广度优先