父类变量初始化问题
子类继承父类slots的变量不能在子类里调用super来初始化吗?
子类继承父类slots的变量不能在子类里调用super来初始化吗?
2021-01-21
可以啊
class Student(Person): __slots__ = ('score',) def __init__(self, name, gender, score): super(Student, self).__init__(name, gender) self.score = score
与
class Student(Person): __slots__ = ('score',) def __init__(self, name, gender, score): self.name = name self.gender = gender self.score = score
效果是一样的
举报