Skip to content
supadhyaya edited this page Jul 24, 2023 · 7 revisions

decorators

decorators in python takes a function as a parameter, does something before & after & then return the grand function. Following is an example

def decorator(func):
    def wrapper():
        print("do something before")
        func()
        print("do something after")
    return wrapper

# any function that undergoes a wrapper must use annotation during function definitio 
@decorator
def hello:
    print("Hello, I am the function")
Clone this wiki locally