Python ProgrammingPython Programming

Decorator with arguments and return value in Python

def calculation(func):
    def wrapper(*args, **kwargs):

        print("Inside the calculation function")

        num_sum = func(*args, **kwargs)
        print("Before return from calculation function")

        return num_sum

    return wrapper


@calculation
def addition(a, b):
    print("Inside the addition function")
    return a + b


print("Sum =", addition(5, 10))
Output
Inside the calculation function
Inside the addition function
Before return from calculation function
Sum = 15