Fabien writes: > On 04/01/2016 03:26 PM, Steven D'Aprano wrote: >> Incorrect. range is a lazy sequence. > > But how does range "know" that it has to start from scratch again? As > in this example: > > it = range(10) > for i in it: > if i >= 3: > break > for i in it: > # why does it start from zero again? > print(i)
The loops are effectively iterating over iter(it) each time. Since "it" is not already an iterator, iter constructs a new one based on "it". Try it = iter(range(10)) to see it not start over. -- https://mail.python.org/mailman/listinfo/python-list