如果子类的__slots__直接在父类基础上增加score属性,输出也正确,有无区别?
class Person(object):
__slots__ = ('name', 'gender')
def __init__(self, name, gender):
self.name = name
self.gender = gender
class Student(Person):
__slots__ = ('name', 'gender', 'score')
def __init__(self, name, gender, score):
self.score = score
s = Student('Bob', 'male', 59)
s.name = 'Tim'
s.score = 99
print(s, s.score, s.name)