Files
Learn-Python-Programming-Th…/ch05/gen.send.py
T
adii1823 ef37ce0c4e ch05
2021-10-28 17:38:16 +05:30

16 lines
330 B
Python

# gen.send.py
def counter(start=0):
n = start
while True:
result = yield n # A
print(type(result), result) # B
if result == 'Q':
break
n += 1
c = counter()
print(next(c)) # C
print(c.send('Wow!')) # D
print(next(c)) # E
print(c.send('Q')) # F