ID EN
Itertools

count

Python 3.11

Make an iterator that returns evenly spaced values starting with number start. Often used as an argument to map() to generate consecutive data points. Also, used with zip() to add sequence numbers. Roughly equivalent to:

Syntax

PYTHON
itertools.count(start=0, step=1)

Examples

Example 1
PYTHON
def count(start=0, step=1):
     count(10) --> 10 11 12 13 14 ...
     count(2.5, 0.5) --> 2.5 3.0 3.5 ...
    n = start
    while True:
        yield n
        n += step

See Also

map() zip()