Decorators in Python - Compulsory Question in Interview


A Decorator in Python is used to modify a function without changing the actual function code.

Decorator is defined using symbol.

Decorator example in Python :-

def fun(func):  #default without return type

    def inner(msg):

        print(msg,"inner")

    return inner    

@fun

def fun2(msg):

    print(msg)

fun2("welcome")

Comments