Python Programming - Tricky Questions - Discussion

Discussion Forum : Tricky Questions - General Questions (Q.No. 16)
16.
What will be the output of the following Python code?
def outer_func(x):
    def inner_func():
        return x + 1
    return inner_func

closure1 = outer_func(5)
closure2 = outer_func(10)

print(closure1() + closure2())
11
16
17
6
Answer: Option
Explanation:
Each closure captures the value of x from its own outer function call, resulting in 6 + 11 = 17.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.