def iterate_range(start, end):
while start < end:
yield start
start += 1
try:
i = iterate_range(3, 5)
print(repr(i))
print(repr(iter(i)))
while True:
print(next(i))
except StopIteration as e:
print('Caught:', repr(e))
Item 16: Iterate Generator
Posted by Logan Chien