0 votes
in Python by
What is a lambda function in Python?

2 Answers

0 votes
by
Sometimes called an “anonymous function,” the lambda function is just like a normal function but is not defined with the keyword. They are defined with the keyword. Lambda functions are restricted to a single line expression, and can take in multiple parameters, just like normal functions.

Here is an example of both normal and lambda functions for the argument (x) and the expression (x+x)

Normal function:

def function_name(x)

return x+x

Lambda function:

lambda x: x+x
0 votes
by

A lambda function is an anonymous function (a function that does not have a name) in Python. To define anonymous functions, we use the ‘lambda’ keyword instead of the ‘def’ keyword, hence the name ‘lambda function’. Lambda functions can have any number of arguments but only one statement.

For example:

l = lambda x,y : x*y

print(a(5, 6))

Output:30

Related questions

0 votes
asked Dec 14, 2019 in Python by sheetalkhandelwal
0 votes
asked Mar 5 in AWS by DavidAnderson
...