0

Please who can explain lambdas in Python for, I've read it over and over please help me out

Python lambdas

19th Mar 2020, 8:58 AM
Emmanuel Anozie
Emmanuel Anozie - avatar
2 ответов
+ 3
lambda is the same as a function (def), except that it doesn't have a name, therefore you can only use it once. Similar to a normal function, lambdas can have 0, 1 or more parameters. Most typically they are used together with higher order functions, like filter or map, which take another function as argument. print(*map(lambda n: n*2+1, range(6))) This is the same as the following: def calc(n): return n*2+1 print(*map(calc, range(6))) But if you write it with the lambda style you won't be able to use the function again in the same code, because it is a one time declaration.
19th Mar 2020, 10:07 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Thank you
19th Mar 2020, 10:09 AM
Emmanuel Anozie
Emmanuel Anozie - avatar