生成器——python

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_30648823/article/details/79848618
#生成器 只有在调用的时候才会生成响应的数据
#只记住当前的位置
#只有 next 方法 不可回退
c = (i*i for i in range(10)) #打印i*i 结果在0-10之间的i
print(c.__next__())

def feib(max):
    n,a,b=0,0,1
    while n<max:
        yield (b)
        a,b = b,b+a
        n+=1
    return "异常信息"
print(feib(10))
f = feib(100)
print(f.__next__())

猜你喜欢

转载自blog.csdn.net/qq_30648823/article/details/79848618