In [1]:
def foo(n):
for i in range(n):
yield f'twice {i} is {2*i}'
In [2]:
g = foo(3)
g
Out[2]:
In [3]:
next(g)
Out[3]:
In [4]:
next(g)
Out[4]:
In [5]:
next(g)
Out[5]:
In [6]:
next(g)
In [7]:
next(foo(5))
Out[7]:
In [8]:
next(foo(5))
Out[8]:
In [9]:
for x in foo(5):
print(x)