class Student(object): __slots__ = ('name','age') class GraduateStudent(Student): __slots__ = ('score',) # pass s = Student() s.name = 'Michael' s.age = 25 # try: # s.score = 99 # except AttributeError as e: # print('AttributeError:', e) g = GraduateStudent() g.score = 99 g.age = 88 print(g.age) print('g.score=', g.score)
__slots__用法
最新推荐文章于 2024-04-19 17:46:43 发布