Generators - call next


We can also use a for loop on the generator and then we don't need to worry about the exception.

examples/generators/simple_generator_next_other.py
def number():
    yield 42
    yield 19
    yield 23

num = number()
print(type(num))
for n in num:
    print(n)

<class 'generator'>
42
19
23