Below is the decorators explanation
Decorators are functions that take another functions as argument to modify its behaviour without changing the function itself. These are useful when we want to dynamically increase the functionality of a function without changing it. Here is an example :
def smart_divide(func):
def inner(a, b):
print("Dividing", a, "by", b)
if b == 0:
print("Make sure Denominator is not zero")
return
return func(a, b)
return inner
@smart_divide
def divide(a, b):
print(a/b)
divide(1,0)
Here smart_divide is a decorator function that is used to add functionality to simple divide function.