Vidyalelo
Python · Q12

Advanced OOP Concepts

Programming · Python · question 12

Q12

What is the purpose of the __slots__ attribute in Python classes?

A.
To define a class as a singleton
B.
To restrict the attributes that can be added to instances
Answer
C.
To define class methods
D.
To define class attributes

Answer: Option B

Solution

Answer: Option B
Solution:
The __slots__ attribute restricts the attributes that can be added to instances, optimizing memory usage.