【问题】多重继承时,super函数只初始化继承的第一个类,不初始化第二个类。
class A(object): def __init__(self): print("init class A") class B(object): def __init__(self): print("init class B") class C(object): def __init__(self): print("init class C") super(C, self).__init__() class D(object): def __init__(self): print("init class D") super(D, self).__init__() class E(A, B): def __init__(self): print("init class E") super(E, self).__init__() class F(C, D): def __init__(self): print("init class F") super(F, self).__init__() if __name__ == '__main__': e = E() f = F()
运行结果:
init class E
init class A
init class F
init class C
init class D
问题:class A和class B没有使用super函数,多重继承时,只初始化继承的第一个类,不初始化第二个类。
What can I do for you ?