Python Programming - Tricky Questions - Discussion

Discussion Forum : Tricky Questions - General Questions (Q.No. 40)
40.
Consider the following Python code:
def my_decorator(func):
    def wrapper(*args, **kwargs):
        result = func(*args, **kwargs)
        return result * 2
    return wrapper

@my_decorator
def my_function(x):
    return x + 1

result = my_function(5)
print(result)
What will be the value of result?
6
10
12
This code will result in an error.
Answer: Option
Explanation:
The decorator multiplies the result of the function by 2.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.