what is lambda in python?

A lambda is an anonymous function in python which is define by using lambda keyword. This function is define without a name, means lambda function is a function which is not having a name.

The syntax of lambda function is very simple.

Syntax: Lambda function

lambda arguments:expression

lambda function takes any number of arguments but can have only one expression.

Example: lambda function with one argument

square= lambda x=x*x
print(square(4))

Output:

16

Example: lambda function with multiple arguments

x=lambda a,b:a*b
print(x(5,6))

Output:

30
Was this article helpful?
YesNo

Leave a Comment