Slots in Python
Slots in Python is a special mechanism that is used to reduce memory of the objects. In Python, all the objects use a dynamic dictionary for adding an attribute. Slots is a static type method in this no dynamic dictionary are required for allocating attribute.
class myClass(object): # defining the slots __slots__ = (par1, par2) def __init__(self, *args, **kwargs): # initializing the values self.par1 = value1 self.par2 = value2
('course', 'price') DSA Self Paced 3999
('course', 'price') oops 5999 System Design 5999 System Design 9999
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course