Python Programming - Classes - Discussion

Discussion Forum : Classes - General Questions (Q.No. 12)
12.
In Python, what is the purpose of the __slots__ attribute in a class?
It specifies the names of class methods.
It defines the list of attributes that instances of the class can have.
It indicates the inheritance hierarchy of the class.
It is used to declare static variables in a class.
Answer: Option
Explanation:
The __slots__ attribute in a class is used to explicitly declare a list of allowed attributes for instances of the class. It can help in saving memory by preventing the creation of additional instance attributes.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.