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.
+ 1
Thank you