class A:
def test(self):
print('A')
# pass
class B(A):
# def test(self):
# print('B')
pass
class C(A):
# def test(self):
# print('C')
pass
class D(B):
# def test(self):
# print('D')
pass
class E(C):
# def test(self):
# print('E')
pass
class F(D,E):
# def test(self):
# print('F')
pass
f1=F()
# f1.test() # 新式类(py3)F-->D--->B--->E--->C---A
# f1.test() # 经典类(py2)F-->D--->B--->A--->E---C
print(F.__mro__) #显示出类F的继承顺序,此方法只有py3有
#在py3都是新式类,是按广度的顺序来继承的,默认最后一个基类会继承object类
#在py2是经典类,是按深度的顺序来继承的
python 类继承方法 python类的继承顺序
转载文章标签 python 类继承方法 文章分类 Python 后端开发
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
python多态继承
python继承
构造函数 多重继承 Python