Python Language itertools.count


Example

Introduction:

This simple function generates infinite series of numbers. For example...

for number in itertools.count():
    if number > 20:
        break
    print(number)

Note that we must break or it prints forever!

Output:

0
1
2
3
4
5
6
7
8
9
10

Arguments:

count() takes two arguments, start and step:

for number in itertools.count(start=10, step=4):
    print(number)
    if number > 20:
        break

Output:

10
14
18
22