摘要: 使用_slots_ 为了达到限制的目的,Python允许在定义class的时候,定义一个特殊的__slots__变量,来限制该class实例能添加的属性: class Student(object): __slots__ = ('name', 'age') # 用tuple定义允许绑定的属性名称然后 阅读全文
posted @ 2018-04-23 15:54 WittPeng 阅读(164) 评论(0) 推荐(0) 编辑