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))

#.....

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.

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

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.

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

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.