1,yeld实现
def fab(max): n, a, b = 0, 0, 1 while n < max: yield b a, b = b, a + b n = n + 1 for i in fab(6): print(i)
输出:
1
12
3
5
8
1,yeld实现
def fab(max): n, a, b = 0, 0, 1 while n < max: yield b a, b = b, a + b n = n + 1 for i in fab(6): print(i)
输出:
1
1