Intermediate
Python
Q80 / 101
What is the purpose of __slots__ in Python classes?
Correct! Well done.
Incorrect.
The correct answer is B) To restrict instance attributes to a predefined list, saving memory by avoiding per-instance __dict__
B
Correct Answer
To restrict instance attributes to a predefined list, saving memory by avoiding per-instance __dict__
Explanation
__slots__ = ["x", "y"] prevents __dict__ creation per instance, reducing memory significantly when creating many instances.
Progress
80/101