Getting to know built-in decorators
Now, the question is, do we have to always create user-defined or custom decorators to be applied to classes and methods, or do we have some pre-defined decorators that can be used for specific purposes.
In addition to the user-defined decorators that we’ve looked at throughout this chapter, Python has its own built-in decorators, such as @staticmethod
and @classmethod
, that can be directly applied to methods. These decorators add certain important functionalities to methods and classes during the process of the class definition itself. We will be looking at these two decorators in detail, as follows.
The static method
The static method – @staticmethod
– is a decorator that takes in a regular Python function as an input argument and converts it into a static method. Static methods can be created inside a class but will not use the implicit first argument of the class object instance usually denoted as an argument named...