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.
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
andandorskip 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.
Related Resources
Tutorial
How to Use Generators and yield in Python
In this step-by-step tutorial, you'll learn about generators and yielding in Python. You'll create generator functions and generator expressions using multiple Python yield statements. You'll also learn how to build data pipelines that take advantage of these Pythonic tools.
For additional information on related topics, take a look at the following resources:
- Python itertools By Example (Tutorial)
- Python's map(): Processing Iterables Without a Loop (Tutorial)
- Python's filter(): Extract Values From Iterables (Tutorial)
- Using the Python zip() Function for Parallel Iteration (Tutorial)
- Python Generators 101 (Course)
- How to Use Generators and yield in Python (Quiz)
- Python's map() Function: Transforming Iterables (Course)
- Filtering Iterables With Python (Course)
- Parallel Iteration With Python's zip() Function (Course)
- Using the Python zip() Function for Parallel Iteration (Quiz)
By Martin Breuss • Updated July 16, 2026