How do you create a range, that contains all the natural numbers?

found this interesting problem on facebook today? I didn"t know the answer for a while, so I asked Daniel on sf to discuss it and see if there was any answer.

question: how do I create a range, that contains all natural numbers?

Feb.28,2021

you can achieve

by using itertools.count () .

reference: python.org/3/library/itertools.html-sharpitertools.count" rel=" nofollow noreferrer "> https://docs.python.org/3/lib.

 

Natural numbers are infinite, and infinity has no practical meaning at the code implementation level. Or to put it another way, the resources of a computer are limited, and it cannot fully accommodate an infinite concept.
if you don't think about resources, just think about implementation, it's easy to define an iterable object in Python, and it's over with + 1 each time.
keep it simple, just use xrange, xrange (1, sys.maxint) .

in addition, the original text refers to numbers, not natural numbers.

Menu