Python gives you a lot of flexibility with objects—but that flexibility comes at a cost. Instances normally carry a per-object dictionary to store attributes, which is powerful but memory‑hungry and a bit slower than it could be.
__slots__ is a mechanism that lets you trade some of that flexibility for:
Lower memory usage per instance Slightly faster attribute access A fixed, enforced set of attributes This article is a detailed, practical guide to __slots__: how it works, when it helps, when it hurts, and how to use it correctly in modern Python.
...