Arguments passing to lambda function | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 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!

24th Dec 2022, 5:57 AM
Ruslan Guliyev
Ruslan Guliyev - avatar
2 Respuestas
+ 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)
24th Dec 2022, 10:33 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Tibor Santa, thank you a lot! You again helped me to understand :)
24th Dec 2022, 7:37 PM
Ruslan Guliyev
Ruslan Guliyev - avatar