In the context of OOP in Python, what is the significance of the __slots__ attribute?
- It defines private methods
- It enables multiple inheritance
- It is used to define instance variables
- It restricts the number of attributes a class can have
The __slots__ attribute in Python is used to restrict the number of attributes (instance variables) a class can have. This can be useful for memory optimization and preventing the accidental creation of new attributes.
Loading...
Related Quiz
- To make the custom objects of a class iterable using a for loop, one should implement the _______ and _______ methods.
- When using Python’s PDB, the command ____ is used to step into a function call.
- To loop through two lists simultaneously, one can use the _______ function in conjunction with a for loop.
- What is the primary difference between a class attribute and an instance attribute in Python?
- In Python, how do you define a method inside a class to access and modify the objects’ attributes?