1def f(): 2 n = 0 3 while True: 4 n = yield n + 1 5 print(n) 6 7g = f() 8try: 9 g.send(1) 10except TypeError: 11 print("caught") 12 13print(g.send(None)) 14print(g.send(100)) 15print(g.send(200)) 16 17 18def f2(): 19 print("entering") 20 for i in range(3): 21 print(i) 22 yield 23 print("returning 1") 24 print("returning 2") 25 26g = f2() 27g.send(None) 28g.send(1) 29g.send(1) 30try: 31 g.send(1) 32except StopIteration: 33 print("caught") 34try: 35 g.send(1) 36except StopIteration: 37 print("caught") 38