python 生成器
1 def f1(): 2 print(11) 3 yield 1 4 5 print(22) 6 yield 2 7 8 print(33) 9 yield 3 10 11 print(44) 12 yield 4 13 14 f11 = f1() 15 ret = f11.__next__() 16 print(ret) 17 ret = f11.__next__() 18 print(ret) 19 ret = f11.__next__() 20 print(ret) 21 ret = f11.__next__() 22 print(ret)
结果:
11
1
22
2
33
3
44
4