I know lambda doesn't have a return expression. Normally
def one_return(a): #logic is here c = a + 1 return c
can be written:
lambda a : a + 1
How about write this one in a lambda function:
def two_returns(a, b): # logic is here c = a + 1 d = b * 1 return c, d
The characteristics of lambda functions are:Lambda functions are syntactically restricted to return a single expression. You can use them as an anonymous function inside other functions. The lambda functions do not need a return statement, they always return a single expression.
Lambda functions does not allow multiple statements, however, we can create two lambda functions and then call the other lambda function as a parameter to the first function.
Python functions can return multiple values. These values can be stored in variables directly. A function is not restricted to return a variable, it can return zero, one, two or more values.
Your function can have multiple triggers. Each trigger acts as a client invoking your function independently. Each event that Lambda passes to your function has data from only one client or trigger.
Yes, it's possible. Because an expression such as this at the end of a function:
return a, b
Is equivalent to this:
return (a, b)
And there, you're really returning a single value: a tuple which happens to have two elements. So it's ok to have a lambda return a tuple, because it's a single value:
lambda a, b: (a, b) # here the return is implicit
Sure:
lambda a, b: (a + 1, b * 1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With