Examveda

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

C. To define class methods

D. To define class attributes

Answer: Option B

Solution (By Examveda Team)

The __slots__ attribute restricts the attributes that can be added to instances, optimizing memory usage.

This Question Belongs to Python Program >> Advanced OOP Concepts

Join The Discussion

Related Questions on Advanced OOP Concepts

What is inheritance in OOP?

A. Creating new objects from existing ones

B. Allowing objects to share attributes and methods

C. Restricting access to object attributes

D. Converting classes into objects