Skip to content

sentinel value

A sentinel value is a special value that an algorithm treats as a signal rather than as ordinary data, most often to mark the end of a sequence or to terminate a loop. Its defining requirement is that it stay distinct from every legitimate value the data can take, so a reading loop can check each value and stop the moment the sentinel appears:

Each value read is tested against the sentinel. A match ends the loop, while any other value is treated as data and processed before the next read.
The Sentinel Is the One Value That Stops the Loop

Sentinels carry meaning in-band, inside the data stream itself, which lets code detect a boundary when no separate length or count is available.

Common Python examples include the empty string that readline() returns at the end of a file, a sentinel object placed on a queue.Queue to signal that no more items are coming, and a stop word that ends an input loop.

The technique breaks down when no value can be spared as the signal, which leads to the semipredicate problem: the sentinel collides with a legitimate result, so code can no longer tell a signal from real data. That risk is why many languages prefer out-of-band signaling through option types, exceptions, or a unique marker object. In Python, calling object() produces a guaranteed-unique sentinel.

Null in Python: Understanding Python's NoneType Object

Tutorial

Null in Python: Understanding Python's NoneType Object

In this tutorial, you'll learn about the NoneType object None, which acts as the null in Python. This object represents emptiness, and you can use it to mark default parameters and even show when you have no result. None is a tool for doing everything with nothing!

basics python

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


By Martin Breuss • Updated July 10, 2026 • Reviewed by Leodanis Pozo Ramos