Python Programming - Tricky Questions - Discussion
Discussion Forum : Tricky Questions - General Questions (Q.No. 6)
6.
What will be the output of the following Python code?
def outer_function(x):
def inner_function():
return x + 1
return inner_function
closure = outer_function(5)
result = closure()
print(result)
Answer: Option
Explanation:
The
inner_function
is a closure that "remembers" the value of x
from its enclosing scope. When closure()
is called, it returns 5 + 1
, resulting in the output 6
.
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers