regularpython@gmail.com
Lambda Function
Lambda function is also called an anonymous function, which means there is no function name.
To create an anonymous function, we don’t need to use def and return keywords. It is a single line function. A lambda function can take any number of parameters, but can only have one expression.
Syntax:
lambda parameters: expression
Example:
def default_value(a,b):
return a+b
# Normal Function
b = default_value(5, 5)
print("Normal Function Result = {}".format(b))
# Anonymous Function
x = lambda x, y: x+y
print("Anonymous Function Result = {}".format(x(5,5)))
Output:
Normal Function Result = 10
Anonymous Function Result = 10