What built-in function returns a range object representing a sequence of numbers?

The story behind the answer

The built-in `range` creates an object representing a sequence of numbers. In Python 3, `range` is technically an immutable sequence type rather than an ordinary function, but it is called with function-like syntax such as `range(5)`.

A range can take one, two, or three integer arguments: `stop`, `start, stop`, or `start, stop, step`. The stop value is excluded, so `range(1, 5)` represents 1 through 4. Its values are generated as needed rather than stored as a full list, keeping memory use small even for very large ranges.

A common mix-up is assuming `range(5)` immediately produces `[0, 1, 2, 3, 4]`. It produces a range object; use `list(range(5))` to materialize a list. Python 2’s `xrange` served a similar lazy purpose, but Python 3 uses `range` for this behavior. The separate `slice` type describes indexing boundaries, not a sequence of numbers.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: