python斐波拉契数列

def fib(max):
    n, a, b = 0, 0, 1
    while n < max:
        print(b)
        a, b = b, a + b
        n = n + 1
    return 'done'

注意,赋值语句:

a, b = b, a + b

相当于:

t = (b, a + b) # t是一个tuple
a = t[0]
b = t[1]
posted @ 2017-02-04 22:30  DevOps_QXW  阅读(218)  评论(0编辑  收藏  举报