Python Function Reference

itertools.count

Produce numbers with the given step endlessly.

Python 3.13
itertools.count(start=0, step=1)

Parameters

startint | floatoptional
The first number, 0 by default.
stepint | floatoptional
The step, 1 by default; it can be a float.

Return value

An infinite iterator of numbers.

Examples

Numbering with zip

Python 3.13
from itertools import count

print(list(zip(count(1), ['a', 'b', 'c'])))
[(1, 'a'), (2, 'b'), (3, 'c')]

The first four numbers with a step of 0.5

Python 3.13
from itertools import count, islice

print(list(islice(count(0, 0.5), 4)))
[0, 0.5, 1.0, 1.5]

Details

The iterator is infinite: list(count()) never finishes. Limit it with zip, itertools.islice or break in a loop.

See also