1、通过 类名.__init__(self)
类名.方法名(self)
School.__init__(self)
School.make_cake1(self)
Master.__init__(self)
Master.make_cake(self)
2.1通过 super进行继承
super()可以避免重复调用
继承属性通过mro列表顺序+1进行继承
class Class1:
def m(self):
print("In Class1")
class Class2(Class1):
def m(self):
print("In Class2")
class Class3(Class1):
def m(self):
print("In Class3")
class Class4(Class2, Class3):
def __init__(self):
super(Class4, self).m()
super(Class2, self).m()
super(Class3, self).m()
obj = Class4()
print(Class4.__mro__) #[4,2,3,1]
# def super(class_name, self):
# mro = self.__class__.mro() #获取mro的列表
# return mro[mro.index(class_name) + 1] #获取自己的索引号,去返回下一个类