0
Can can someone explain lambdas in python?
The lesson tells me bugger all about the syntax of it and what it means
2 Respostas
+ 2
A Lambda Function in Python programming is an anonymous function or a function having no name. It is a small and restricted function having no more than one line. Just like a normal function, a Lambda function can have multiple arguments with one expression.
Syntax and Examples
The formal syntax to write a lambda function is as given below:
lambda p1, p2: expression
Here, p1 and p2 are the parameters which are passed to the lambda function. You can add as many or few parameters as you need.
However, notice that we do not use brackets around the parameters as we do with regular functions. The last part (expression) is any valid python expression that operates on the parameters you provide to the function.
Example
Now that you know about lambdas let’s try it with an example. So, open your IDLE and type in the following:
adder = lambda x, y: x + y
print (adder (1, 2))
the output:
3
0
https://www.sololearn.com/discuss/1802398/?ref=app
https://www.sololearn.com/discuss/1179478/?ref=app
https://www.sololearn.com/discuss/2038344/?ref=app
https://www.sololearn.com/discuss/1675905/?ref=app
https://www.sololearn.com/discuss/1603444/?ref=app
https://www.sololearn.com/discuss/1598709/?ref=app
https://www.sololearn.com/discuss/2180319/?ref=app