python面向对象-多继承区别

#!/usr/local/bin/python3
# -*- coding:utf-8 -*-

'''

构造方法继承策略:
    在python2中,经典类是按照深度优先继承构造方法的;新式类是按照广度优先继承构造方法的
    在python3中,经典类和新式类都是按照广度优先继承构造方法的

'''
class A(object):
    def __init__(self):
        print("A")

class B(A):
    pass
    # def __init__(self):
    #     print("B")

class C(object):
    pass
    # def __init__(self):
    #     print("C")

class D(B, C):  #优先找B中的,如果B中没有,则去C中找;如果C中也没有则去C的父类中找,最后去B中的父类中找
    pass
    # def __init__(self):
    #     print("D")
d1 = D()

  

猜你喜欢

转载自www.cnblogs.com/octopuszy/p/9064725.html