Understand __slots__ in Python

A simple way to improve your Python code

Xiaoxu Gao
Towards Data Science
6 min readMay 31, 2020

--

Photo by m on Unsplash

When we create an object from a class, the attributes of the object will be stored in a dictionary called __dict__. We use this dictionary to get and set attributes. It allows us to dynamically create new attributes after the creation of the object.

--

--

I’m a Developer with a focus on Python and Data Engineering. I write stuff to talk to myself and the world. You can find me on linkedin.com/in/xiaoxugao/.