#Author:clarkclass 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 中经典类和新式类都遵循广度优先原则
时间: 2024-09-29 17:23:47