Quick Answer
__slots__ declares a fixed set of attributes for a class, replacing the per-instance __dict__. Benefits: lower memory usage (no dict overhead per instance), slightly faster attribute access, prevents dynamic attribute creation. Use when creating many instances of a small class. Downside: less flexible, can't add new attributes dynamically, inheritance with slots requires care.
Answer
__slots__ restricts dynamic attribute creation. Saves memory by preventing per-instance __dict__. Useful for memory-sensitive applications or many small objects.
S
SugharaIQ Editorial Team
Verified Answer
This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.