This allows for dynamic variable creation but can also lead to uncaught errors. The _dict_ attribute is a dictionary whose keys are the variable names and whose values are the variable values. By default, when Python creates a new instance of a class, it creates a _dict_ attribute for the class. The short answer is slots are more efficient in terms of memory space and speed of access, and a bit safer than the default Python method of data access.
It also prevents the creation of any variables that aren't declared in _slots_. The _slots_ declaration allows us to explicitly declare data members, causes Python to reserve space for them in memory, and prevents the creation of _dict_ and _weakref_ attributes. _slots_ is a class variable that is usually assigned a sequence of strings that are variable names used by instances. The first thing we should understand is that _slots_ is only used in the context of Python classes.
_slots_ are discussed in the Python Language Reference under section 3.3.2, Customizing Attribute Access. This article will explain what they are, how, and why to use them, and when not to use them. Others say that they are badly understood, tricky to get right, and don't have much of an effect unless there are many instances of objects that use them. On the one hand, they are considered to be popular. _slots_ has a mixed reputation in the Python community.