码迷,mamicode.com
首页 > 编程语言 > 详细

python 2 和 python 3的继承

时间:2017-08-20 16:55:33      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:color   odi   coding   python   ini   优先   深度   class   code   

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 广度优先

python 2 和 python 3的继承

标签:color   odi   coding   python   ini   优先   深度   class   code   

原文地址:http://www.cnblogs.com/csy113/p/7400286.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!