In [1]:
def gen():
message = 'Hello'
while True:
print('gen: ready to yield %r' % message)
item = yield message
print('gen: got %r' % item)
message = 'message for %s' % item
In [2]:
g = gen()
g
Out[2]:
In [3]:
a = next(g)
a
Out[3]:
In [4]:
a = g.send('one')
a
Out[4]:
In [5]:
a = g.send('two')
a
Out[5]: