Using iterator with next


A feature of any iterator is that we could iterate over it using the next call.

examples/iterators/simple_iterator_next.py
from counter import Counter

cnt = Counter()

while True:
    try:
        a = next(cnt)
        print(a)
    except Exception as ex:
        print(ex.__class__.__name__)
        break

1
2
3
StopIteration