0 votes
in Python by (30.8k points)
What is a lambda function in Python?

2 Answers

0 votes
by (30.8k points)
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 (30.8k points)

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))


Related questions

+1 vote
0 votes
0 votes