super函数
super(type, obj) 返回绑定超类的实例
super() 返回绑定超类的实例,等同于:
super(class, 实例方法的第一个参数)
(必须在方法内调用)
class Human:
def init(self, n, a):
‘’‘此方法为人的对象添加,姓名和年龄属性’’’
self.name = n
self.age = a
def infos(self):
print(“姓名:”, self.name)
print(“年龄:”, self.age)
class Student(Human):
def init(self, n, a, s=0):
super().init(n, a)
self.score = s
def infos(self):
super().infos()
# print("姓名:", self.name)
# print("年龄:", self.age)
print("成绩:", self.score)