Next / Previous / Contents / TCC Help System / NM Tech homepage

20.28. next(): Call an iterator

This function attempts to get the next value from some iterator I (see Section 24.2, “Iterators: Values that can produce a sequence of values”). (New in version 2.6.)

next(I[, default)

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