推荐链接:https://blog.csdn.net/mieleizhi0522/article/details/82142856
梨子:
#!/usr/bin/python
#coding=utf-8
def fib(n):
a,b = 0,1
for _ in range(n):
a,b = b,a+b
yield a
def main():
for val in fib(10):
print(val)
if __name__ == '__main__':
main()
#yield关键字把普通函数变成生成器对象