# Lambda Function

> A small function in one line, often with no name. You use it once.

**Field:** Software Development  
**Category:** Programming Paradigms  
**Also known as:** Lambda, Anonymous Function, Arrow Function

## Think of it like

Think of it like a sticky note with one quick job on it. You use it once and throw it away.

## Definition

A lambda is a small function written in one line, often with no name. You use it where a function is needed just once, like inside map or sort. Python writes it with the word lambda; JavaScript uses an arrow, like (x) => x * x. It can hold only a short piece of code. For anything longer, a normal named function is clearer.

## Example

Jack sorts a list of players by score with a lambda. The whole rule for sorting fits inside the sort call.

## Example code

```python
>>> square = lambda x: x * x
>>> square(4)
16
```

A one-line function that squares a number.

## Why it matters

Lambdas keep a tiny rule right where it is used. You do not need to jump elsewhere to read it.

## Common mistake

Packing a long rule into one lambda. If it needs a comment to read, give it a name instead.

## Three principles

- **One line.** A short piece of code.
- **Often nameless.** Used in one place.
- **Arrow or lambda.** Same idea, two spellings.

## Related terms

- [Higher-Order Function](https://learn.benibix.com/term/development/higher-order-function)
- [Function](https://learn.benibix.com/term/development/function)
- [Closure](https://learn.benibix.com/term/development/closure)
- [Map, Filter and Reduce](https://learn.benibix.com/term/development/map-filter-reduce)

## Told apart from

- [Lambda vs Closure](https://learn.benibix.com/compare/lambda-vs-closure): A lambda is a short function with no name. A closure is a function that keeps the variables from where it was made. A lambda can be a closure, but the two words mean different things.

---

Source: https://learn.benibix.com/term/development/lambda
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
