Fabien <fabien.mauss...@gmail.com>:

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

The "for .. in" statement invokes the __iter__() method of the iterable
object to get an iterator (maybe via the builtin iter() function).

Iterators have an __iter__() method as well which returns the iterator
itself.

Thus,

   >>> it = iter(range(10))
   >>> it is iter(it)
   True


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to