继承的时候,调用父类的构造函数的方法:使用super()函数,只需要调用一次就行,会自动调用所有父类和父类的父类的构造函数
# -*- coding: utf-8 -*- class A(object): def __init__(self): super(A, self).__init__() print("A__init__") class B(object): def __init__(self): super(B, self).__init__() print("B__init__") class C(A, B): def __init__(self): super(C, self).__init__() # 等价 super().__init__() print("C__init__") x = C()
输出为: