This is a closure. A function inside a function.
The inner function has access to objects of the outer function.
The function
The inner function has access to objects of the outer function.
The function
bar
access x
from foo
's scope.def foo(x): def bar(y): return x*y return barCalling foo(), will return a function object:
Output:<function __main__.foo.<locals>.bar(y)>
You've to call the returned function bar
to get the return value from bar
.func = foo(13) # or in one line # result = foo(13)(42) result = func(42) print(result)
Output:546
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!