Explain the difference between @staticmethod, @classmethod, and regular instance methods.
Explain the difference between @staticmethod, @classmethod, and regular instance methods.
Student
The Anubhav portal was launched in March 2015 at the behest of the Hon'ble Prime Minister for retiring government officials to leave a record of their experiences while in Govt service .
In Python classes,
@staticmethod,@classmethod, and regular instance methods differ in how they receive and use their first argument and how they relate to the class and its instances.1. Regular Instance Methods
self(the instance itself)2. @staticmethod
selforclsas the first argument.self) or class (cls) data.3. @classmethod
cls(the class itself).Summary Table
selfobj.method()Class.method()orobj.method()clsClass.method()orobj.method()