Python has an interesting feature called Decorators to add functionality to an existing code. Decorators are a very powerful and useful tool in Python since it allows programmers to modify the behavior of function or class.
In Decorators, functions are passed as an argument into another function and then called inside the wrapper function.
When to use Decorator :
We’ll use a decorator when we need to change the behavior of a function without modifying the function itself. A few good examples are when we want to add logging, test performance, perform caching, verify permissions, and so on.
We can also use one when we need to run the same code on multiple functions. This avoids you writing duplicating code.