What is decorator in python

·

1 min read

As a developer best way to write code within a function or class. but what if our code enter in function and return exception error. Decorator is function which validate the passing parameter in function. if parameter is valid then code enter in the function block otherwise code didn't enter into it.

Screenshot 2021-09-01 at 5.38.15 PM.png

first we use decorator_function and it goes to inner function validate, if number is greater then 0 the it return the function otherwise print message and it can't enter the factorial function.

how we use decorator in function:

Screenshot 2021-09-01 at 5.38.28 PM.png

now call this function and print the result print(factorial(5))