This function attempts to get the next value from some
Section 24.2, “Iterators: Values that can produce a sequence of
values”). (New in version 2.6.)
If the iterator produces another value, that value is returned by this function.
If the iterator is exhausted and you provide a
that value is returned.
If the iterator is exhausted and you do not provide a
default value, the
next() function raises a
Here is an example.
>>> it = iter(xrange(0,2)) >>> next(it, 'Done') 0 >>> next(it, 'Done') 1 >>> next(it, 'Done') 'Done' >>> next(it) Traceback (most recent call last): File "<stdin>", line 1, in <module> StopIteration