ADVERTISEMENT
ADVERTISEMENT

Python program to illustrate the working of decorators

Here, we are writing a Python program to see how the decorators work?
Submitted by Shivang Yadav, on March 12, 2021

Decorator is the concept in a program which takes a function, adds some functionality and returns it.

Program to illustrate the working of decorators

def decorate(fun):
    def newfun():
        print("Start")
        fun()
        print("Stop")
    return newfun

@decorate
def work():
    print("I am Working")

work()

Output:

Start
I am Working
Stop

Python class & object programs »



ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.