A lambda function is a small anonymous function.

A lambda function can take any number of arguments, but can only have one expression.


s1 = 'GeeksforGeeks'

s2 = lambda func: func.upper()
print(s2(s1))

Output

GEEKSFORGEEKS

Python Lambda Function Syntax

Syntax: lambda arguments : expression

lambda with Condition Checking

A lambda function can include conditions using if statements.

Example:

# Example: Check if a number is positive, negative, or zero
n = lambda x: "Positive" if x > 0 else "Negative" if x < 0 else "Zero"

print(n(5))   
print(n(-3))  
print(n(0))

Output

Positive
Negative
Zero

Explanation: