Generators - call next
We can also use a for
loop on the generator
and then we don't need to worry about the exception.
def number():
yield 42
yield 19
yield 23
num = number()
print(type(num))
for n in num:
print(n)
Output:
<class 'generator'>
42
19
23