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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *