#Author:clark
class Original(object):#在python 3 中写上object的新式类和不写的经典类遵循的都是广度优先原则
def __init__(self):
print("in Original")
class Second(Original):
pass
# def __init__(self):
# print("in the second")
class Third(Original):
def __init__(self):
print("in the third")
class Last(Second,Third):
pass
# def __init__(self):
# print("in the last")
last_obj = Last()
运行结果为:
in the third
如果在python2中经典类结果为
in Original
新式类的结果为
in the third
可以在python2环境中试一下
总结:
python2 中经典类遵循深度优先原则,新式类遵循广度优先原则
python3 中经典类和新式类都遵循广度优先原则