<jupyter_start><jupyter_text>By default, Python stores the attributes of each instance in a dict named__dict__. As we saw in “Practical Consequences of How dict Works”, adict has a signficant memory overhead—even with the optimizationsmentioned in that section. But if you define a class attribute named__slots__ holding sequence of attribute names, Python uses analternative storage model for the instance attributes: the attributes named in__slots__ are stored in a hidden array or references that uses lessmemory than a dict. Example 11-13. The Pixel class uses `slots.<jupyter_code>class Pixel:
    __slots__ = ('x', 'y')
p = Pixel()
p.__dict__<jupyter_output><empty_output><jupyter_text>Now let’s create a subclass of Pixel to see thecounterintuitive side of __slots__:Example 11-14. The OpenPixel is a subclass of Pixel.<jupyter_code>class OpenPixel(Pixel):
    pass
op = OpenPixel()
op.__dict__<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.061224489795918366, 'fraction_numerical': 0.008592910848549946, 'mean_word_length': 5.852941176470588, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '88780', 'license': 'MIT', 'n_tokens_mistral': 278, 'n_tokens_neox': 261, 'n_words': 114, 'path': 'chapter 11- A Pythonic Object/example 11-13-Saving Memory with __slots__.ipynb', 'repo_name': 'Jalilnkh/KartalOl-Fluent-Python-2022', 'size': '931'}