What is the difference between @staticmethod and @classmethod?
@staticmethod function is nothing more than a function defined inside a class. It is callable without instantiating the class first. It’s definition is immutable via inheritance. @classmethod function also callable without instantiating the class, but its definition follows Sub class, not Parent class, via inheritance.
class Employee: @classmethod def classmthd(*args): return args @staticmethod def staticmthd(*args): return args print(Employee.classmthd()) print(Employee.classmthd('test')) print(Employee.staticmthd()) print(Employee.staticmthd('test'))
Sample output of above program.
(class '__main__.Employee',) (class '__main__.Employee', 'test') () ('test',)
2019-07-09T02:56:59+05:30
2019-07-09T02:56:59+05:30
Amit Arora
Amit Arora
Python Programming Tutorial
Python
Practical Solution