Skip to main content

Python Tutorial 5.3 - Lambda Functions in Python

Welcome to the “Lambda Functions” tutorial!


Overview

Lambda functions are anonymous, single-expression functions.

Syntax

lambda arguments: expression

Example

multiply = lambda x, y: x * y
print(multiply(4, 5))  # 20

When to Use

  • Short callbacks (e.g., in map(), filter(), sorted()).
  • Inline, throwaway functions.
nums = [1, 2, 3, 4]
squared = list(map(lambda n: n**2, nums))

Key Takeaways

  • No def or return.
  • Best for simple, short operations.

Happy coding!

Comments