首页 > 编程语言 > 详细

Python自学之乐-python 2、python 3中经典类、新式类的深度和广度优先小结

时间:2017-09-17 17:22:45      阅读:336      评论:0      收藏:0      [点我收藏+]
#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 中经典类和新式类都遵循广度优先原则

Python自学之乐-python 2、python 3中经典类、新式类的深度和广度优先小结

原文:http://www.cnblogs.com/clarkxhb/p/7536120.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!