1、super(子类名,self).__init__(继承变量名1,继承变量名2)
#无需输入参数
class person:
def __init__(self):
self.num = 10
def Ffd(self):
return 'hello world'
class superman(person):
def __init__(self):
super(superman, self).__init__()
self.a = self.num
i = superman()
print(i.a)
#需要输入参数
class person:
def __init__(self, num):
self.num = num
def Ffd(self):
return 'hello world'
class superman(person):
def __init__(self, num):
super(superman, self).__init__(num)
self.a = self.num
i = superman(10)
print(i.a)
2、父类名.__init__(self,继承变量名1,继承变量名2)
#无需输入参数
class person:
def __init__(self):
self.num = 10
def Ffd(self):
return 'hello world'
class superman(person):
def __init__(self):
person.__init__(self)
self.a = self.num
i = superman()
print(i.a)
#需要输入参数
class person:
def __init__(self, num):
self.num = num
def Ffd(self):
return 'hello world'
class superman(person):
def __init__(self, num):
person.__init__(self, num)
self.a = self.num
i = superman(10)
print(i.a)