1.生成器
只有在调用时才生成相应的数据,只记录当前位置,只有一个__next__()方法.
def fib(max): n,a,b = 0,0,1 while n < max: #print(b) yield b a,b = b,a + b n = n + 1 return ‘done‘ f = fib(6) while True: try: x = next(f) print(‘f:‘,x) except StopIteration as e: print(‘Generator return value:‘,e.value) break