Answer the question
In order to leave comments, you need to log in
Explain how this code works, I don't understand these parenthesis manipulations?
def f():
def a():
def b():
print("nested function")
return b
return a
f()()()
Answer the question
In order to leave comments, you need to log in
As a comment to all answers:
One must distinguish between a function object and a call to the result of a function evaluation.
The object is f
Calling the result is f()
This is where the trick is based.
f() becomes a
a() becomes b
b() becomes print("nested function")
This prints a string.
Xs as it is called but here each bracket is responsible for each internal function in the order in which they are declared.
In the code, the description of a function in a function... It's like a variable in a variable, only this function. As a result, the return of functions without their execution.
And then they are called with parentheses to execute them.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question