Classmethod Decorator
Below are the main features of classmethids.
Classmethod decorator. The classmethods first argument is always a class cls similar to an instance method receiving self as its first argument. The classmethod decorator is an inbuilt function decorator that gets evaluated after the function is defined. The classmethod Decorator This decorator exists so you can create class methods that are passed the actual class object within the function call much like self is passed to any other ordinary instance method in a class.
The staticmethod is a built-in decorator that defines a static method in the class in Python. Syntax for Class Method. This decorator exists so you can create class methods that are passed the actual class object within the function call much like self is passed to any other ordinary instance method in a class.
Classmethod is considered un-Pythonic so in newer Python versions you can use the classmethod decorator for classmethod definition. A static method doesnt receive any reference argument whether it is called by an instance of a class or by the class itself. For class methods we need to specify classmethod decorator and for static method staticmethod decorator is used.
This decorator will allow us to call that method using the class name instead of the object. The result of that evaluation shadows your function definition. We just use the decorator classmethod before the declaration of the method contained in the class and then we can directly access the method.
According to the Python documentation. Expand the box below for an example using these decorators. The following notation is used to declare a static method in a class.
Python classmethod using Decorator. It can be called either on the class such as Cf or on an instance such as Cf. The result of that evaluation shadows your function definition.