# Lambda Functions — Python Fundamentals: From Basics to Async

Source: https://www.skillbyai.com/en/python/py-lambda

> Write short anonymous functions with lambda for sort keys and callbacks, and know when a def is clearer.

## One-line functions

A `lambda` is a nameless function limited to a single expression — handy as a short-lived argument.

```python
square = lambda n: n * n
print(square(5))   # 25

people = [("Ada", 36), ("Bo", 24)]
people.sort(key=lambda p: p[1])
print(people)
```

## When to use lambda

Use `lambda` for throwaway callbacks (`sort`, `filter`, `map`); for anything with logic or a name worth reusing, write a normal `def`.
