itertools.count() function in Python 3

import itertools
iter = itertools.count(start=0, step=1)
next(iter) \\ 0
next(iter) \\ 1
next(iter) \\ 2
next(iter) \\ 3

itertools.count() is to generate continuous integers, the default step is 1 and the default started number is 0, you can adjust it by your preference.

But warning: if you close the program and restart it, the number will be begin with start, not the prcedding of the last number when we closed the program.

I have not yet found the way to continue to count the number since the program closed and restarted.

posted @ 2024-10-25 16:49  HelenHung  阅读(14)  评论(0)    收藏  举报