python3- __slots__

  Python允许在定义class的时候,定义一个特殊的__slots__变量,来限制该class实例能添加的属性:

class Student(object):
    __slots__ = ('name', 'age') # 用tuple定义允许绑定的属性名称

  如果子类中也定义__slots__,那么,子类实例允许定义的属性就是自身的__slots__加上父类的__slots__

原文地址:https://www.cnblogs.com/GYoungBean/p/6281459.html