生成器: def fib(max): a, b = 0, 1 while a < max: a, b = b, a + b yield afor 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
posted on 2015-09-22 16:58 sudo987 阅读(133) 评论(0) 编辑 收藏 举报