+ 1
Arguments passing to lambda function
Hello dear coders, Could you please explain how arguments are passed to the following function: def test(n): return lambda x: x+n f = test(230) print(f(5)) Appreciate your support!
2 Respostas
+ 4
If you try this:
print(type(f))
You see that the type of f is a function. We can also call it a closure, it is an anonymous function returned from test, that is still expecting an argument to work.
When we do test(230) it gives us a function which adds 230 to a number that we pass to it.
Writing
f(5)
is the same as writing
test(230)(5)
+ 1
Tibor Santa, thank you a lot! You again helped me to understand :)