What is the output of the following Python code snippet?
def mul(n):
def inner(x):
return x * n
return inner
print(mul(2)(4))
def inner(x):
return x * n
return inner
print(mul(2)(4))
Correct answer
B. 8
6 views
B. 8
6 views
The inner function remembers the value of n from the outer function.
Asked in: Python Interview Functions
https://docs.python.org/3/tutorial/controlflow.html#defining-functionsNot sure why the answer is B? Ask here and get an explanation.