show me the code
def fab(max):
n, a, b = 0, 0, 1
while n < max:
yield b
# print b
a, b = b, a + b
n = n + 1
...
>>> for n in fab(5):
... print n
...
1
1
2
3
5
yield一般用在用循環(huán)功能的函數(shù)內(nèi),用在把循環(huán)里的數(shù)據(jù)提取出來(lái),有點(diǎn)像OC的block