The range object is iterable. However, it's not an iterator.
To get an iterator, you need to call iter() first:
>>> r=range(5,15)
>>> next(iter(r))
5
>>> next(iter(r))
5
>>> next(iter(r))
5
>>> next(iter(r))
5
>>> i=iter(r)
>>> next(i)
5
>>> next(i)
6
>>> next(i)
7
>>> next(i)
8
>>> iter(r)
>>> iter(r)
>>> iter(r)
Edit: But be careful not to call iter()
with every call to next()
. It creates a new iterator at index 0.