请问子类是只能从父类中继承所有属性吗?
请问子类是只能从父类中继承所有属性吗?他可以只从父类中继承部分属性吗?
对此,我做了以下代码测试:
class Person(object): def __init__(self,name,gender): self.name=name self.gender=gender class Teacher(Person): def __init__(self,name,course): super(Teacher,self).__init__(name) self.course=course t1=Teacher('zhang','Chinese') print(t1.name) #print(t1.gender) print(t1.course)
然后报错了
TypeError: __init__() missing 1 required positional argument: 'gender'