标签:
生成器: def fib(max): a, b = 0, 1 while a < max: a, b = b, a + b yield a
for x in fib(10):
print x,
>>>
1 1 2 3 5 8 13
指定生成某一个: def fib(n): a, b = 0, 1 while n: a, b, n = b, a+b, n - 1 return a
标签:
原文地址:http://www.cnblogs.com/iNeoWong/p/4829479.html