关于继承,报错 ''__init__'' missing 1 required positional argument"score"(__init__缺少1个必需的位置参数score)
我把教学的代码复制回来,改成Student继承 Person的 name, gende,Teacher继承Student的name, gende。运行后就如题报错了。然后在Teacher那里多加了score,就能运行了。这算什么?只能继承全部,然后覆写或变私有?
class Person(object):
def __init__(self, name, gender):
self.name = name
self.gender = gender
class Student(Person):
def __init__(self, name, gender, score):
super(Student, self).__init__(name, gender)
self.score = score
class Teacher(Student):
def __init__(self, name, gender, course):
super(Teacher, self).__init__(name, gender) #此处报错
self.course = course
p = Person('Tim', 'Male')
s = Student('Bob', 'Male', 88)
t = Teacher('Alice', 'Female', 'English') #和此处报错