Decorators in Python with Examples
Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python
Program 1
def mydecorate(myfactorial):
def mywrapper():
print("***Program for Factorial*******")
n=int(input("Enter a Number"))
myfactorial(n)
print("***End of Program for Factorial*******")
return mywrapper
def factorial(n):
f=1
while(n!=0):
f=f*n
n=n-1
print("Factorial is ",f)
fun1=mydecorate(factorial)
fun1()
# def mydecorator(myfunction): # Decorator
# def mywrapper():
# print("*********This is begin of function**********")
# myfunction() # Orignal function
# print("-----------This is end of function------------------")
# return mywrapper
# def myfun():
# print("This is my orignal function Myfun ")
# fun1=mydecorator(myfun)
# fun1()
Did you like this article? If Yes, please give DataFlair 5 Stars on Google

