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 »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.