0

Lambda question

why does this code prints 666? The function returns a lambda function or actually it returns 3 functions (due to the range?). When I then pass 3 as an argument - what happens? As simple as this looks I don’t get it yet. def ll(): return [lambda x:i*x for i in range(3)] for l in ll(): print(l(3), end="")

17th Apr 2019, 5:08 AM
Karsten Stiegler
Karsten Stiegler - avatar
2 Réponses
+ 2
https://docs.python.org/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result
17th Apr 2019, 6:00 AM
Diego
Diego - avatar
+ 1
Thanks a lot! RTFM advice to me ... but the manuals are so long :)
17th Apr 2019, 6:02 AM
Karsten Stiegler
Karsten Stiegler - avatar