range()

A built-in that produces a sequence of whole numbers on demand, such as range(5) for 0, 1, 2, 3, 4.

In more detail

range(stop) counts from 0 up to but not including stop; range(start, stop) and range(start, stop, step) set the start and the step, which may be negative to count down. It is mostly used in for loops and does not build a list unless you ask with list(range(...)).

Example

list(range(10, 0, -2))   # [10, 8, 6, 4, 2]

Related terms

Taught in

References

Certification courses