Skip to content

lazy evaluation

Lazy evaluation is an evaluation strategy that delays computing an expression until its result is actually needed, then reuses that result instead of recomputing it. It is the opposite of eager, or strict, evaluation, which computes every expression as soon as it is bound, whether or not the program ever reads the value.

A lazy language wraps each pending expression in a thunk, a suspended computation that runs the first time its value is forced. Whether the forced value is cached separates the two main variants: call-by-need caches it after the first force, while call-by-name re-runs the thunk on every use.

A pending expression is wrapped in a thunk that the first use forces, then it splits into call by need, which caches and reuses, and call by name, which recomputes.
How a Thunk Defers and Then Forces a Value

Because work happens only on demand, a program can model an infinite sequence, such as all the prime numbers, and consume just the finite prefix it reads.

Lazy evaluation surfaces in several recurring forms:

  • Short-circuit operators, where Boolean operators like and and or skip their second operand once the result is settled.
  • Lazy data structures, such as streams and Python’s generators, that produce items on demand.
  • Control abstractions, where deferring an argument lets an ordinary function stand in for custom control flow.

The strategy trades a known cost for a deferred one. Skipping unused work saves time and memory, but unforced thunks can instead leak it, and the indeterminate order of deferred computations complicates side effects like input and output. Languages such as Haskell are lazy by default, while most others, including Python, expose laziness through opt-in tools like generators and iterators.

What's Lazy Evaluation in Python?

Tutorial

What's Lazy Evaluation in Python?

This tutorial explores lazy evaluation in Python and looks at the advantages and disadvantages of using lazy and eager evaluation methods. By the end of this tutorial, you'll clearly understand which approach is best for you, depending on your needs.

intermediate python

For additional information on related topics, take a look at the following resources:

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Martin Breuss • Updated Oct. 22, 2026