This function attempts to get the next value from some
iterator (see
Section 24.2, “Iterators: Values that can produce a sequence of
values”). (New in version 2.6.)
I
next(I[,default)
If the iterator produces another value, that value is returned by this function.
If the iterator is exhausted and you provide a value,
that value is returned.
default
If the iterator is exhausted and you do not provide a
default value, the next() function raises a
StopIteration exception.
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