Published Aug 12, 2022
[
 
]
__slots__
allow us to explicitly declare data members (like properties) and
deny the creation of __dict__
and __weakref__
(unless explicitly declared in
__slots__
or available in a parent.)
The space saved over using __dict__
can be significant. Attribute lookup speed
can be significantly improved as well.
object.__slots__
__slots__
reserves space for the declared variables and prevents the automatic creation of __dict__
and __weakref__
for each instance.