1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| def count(n): print "Counting" a = 1 while n > 0: print "Before yield" yield n n -= 1 print "End yield" print a print "---------\n" def diedai_Count(): for i in count(5): print i def fibonacci(): a=b=1 yield a yield b while True: a,b = b,a+b yield b def Generate_Fibonacii(): for num in fibonacci(): if num > 100: break print num def nullYield(): a = 1 yield a def gen_nullyield(): for i in nullYield(): if i == 2: print i else: print "Nothing" gen_nullyield()
|