Lambda Function in Python

In Python, an anonymous function, also known as lambda function, is a function that is defined without a name. While normal functions are defined using the def keyword in Python, anonymous functions are defined using the lambda keyword. Hence, anonymous functions are also called lambda functions.

Syntax lambda arguments: expression

Example: Basic Lambda Function.

Python

# Normal function
def add(a, b):
    return a + b

# Lambda function
add_lambda = lambda a, b: a + b

# Both work the same way
print(add(3, 5))        # Output: 8
print(add_lambda(3, 5)) # Output: 8

Explanation: