Nearby lessons

67 of 108

Python - Lambda Functions

What Is a Lambda Function?

A lambda function is a small anonymous function written in a single line.

It is often used for short, simple operations.

Syntax

lambda arguments: expression

Examples

s = lambda n: n * n
print(s(4))

add = lambda a, b: a + b
print(add(10, 20))

Common Uses

  • filter()
  • map()
  • reduce()

Why Use Lambda?

Lambda functions help us write concise code when we only need the function once.

Summary

Term Meaning
LambdaAnonymous one-line function
filter()Selects items based on a condition
map()Applies a function to each item
reduce()Reduces values into one result

🧠 Test Your Knowledge

3 Questions

Progress: 0 / 3
Keep Going!Python - Modules