1. Home
  2. Data Science
  3. Python
  4. What does __slots__ do in a class in Python?

Added 25 Nov 2026

What does __slots__ do in a class in Python?

  1. Defines time slots
  2. Creates a thread pool
  3. Restricts attributes and saves memory by avoiding a per-instance __dict__ Correct answer
  4. Sorts attributes

Correct answer

C. Restricts attributes and saves memory by avoiding a per-instance __dict__

5 views

MCQSEXAM

Explanation

__slots__ fixes the set of attributes, reducing memory use.

Reference

Asked in: Python Interview OOP

https://docs.python.org/3/tutorial/classes.html

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs