AlgoMaster Logo

__slots__

Last Updated: May 22, 2026

Low Priority
9 min read

Every regular Python instance carries a hidden dictionary called __dict__ that stores its attributes. That dict is flexible (you can attach any attribute at any time), but it costs real memory per object. __slots__ is a class-level declaration that swaps the dict for a fixed slot layout, shrinking each instance and locking the attribute set down. This lesson covers the layout difference, how to measure the savings, the inheritance rules that trip people up, and when slots actually pay off.

Premium Content

Subscribe to unlock full access to this content and more premium articles.