Python: Which statement about __slots__ is the strongest interview answer?

Difficulty:

Easy

Questions:

1

Time Limit:

2 minutes

Passing Score:

100%

Question

Which statement about __slots__ is the strongest interview answer?

  1. __slots__ can restrict instance attributes and reduce per-instance memory overhead by avoiding the normal instance dictionary in some cases.
  2. __slots__ is mostly a naming style choice and has little effect on runtime behavior or design tradeoffs.
  3. __slots__ exists mainly to reduce the number of files in a Python project.
  4. __slots__ matters only for frontend scripting and not for backend or automation code.

Hint

Start with the core rule behind __slots__.

Answer and rationale

Correct answer: A. __slots__ can restrict instance attributes and reduce per-instance memory overhead by avoiding the normal instance dictionary in some cases.

__slots__ can restrict instance attributes and reduce per-instance memory overhead by avoiding the normal instance dictionary in some cases. This is the base concept interviewers commonly test first.

Track: Python