ExampleEdit & Run
from itertools import count

seq = count(0, 2) #an infinite sequence of even numbers

print(next(seq))
print(next(seq))
print(next(seq))
print(next(seq))
print(next(seq))

#.....
copy
Output:
0 2 4 6 8 [Finished in 0.011350218672305346s]

The itertools module in the standard library provides a number of tools for working with iterables.

The count() function in the module creates an iterator which yields infinite sequence of integers from a starting point and incrementing by the specified amount with each step.

Syntax:
count(start = 0, step = 1)
copy
start The starting value. It defaults to 0.
step The value to be used for incrementing after each iteration. It defaults to 1.
Parameters:

The function returns an iterator which generates an infinite sequence of integers starting from the 'start' value and incrementing by the 'step' value with each iteration.

ExampleEdit & Run
from itertools import count

seq = count(0, 5)

for i in seq:
    print(i) 
    if i == 25: 
       break 

#do something else

#continue from where you left off
for i in seq:
    print(i)
    if i == 50:
        break

#you can go on forever
copy
Output:
0 5 10 15 20 25 30 35 40 45 50 [Finished in 0.011560793034732342s]

Using the count() function is more efficient and fast than using range() to generate the numbers. This is because count() function doesn't have to store all the numbers in memory, instead it generates them one at a time as needed.