斐波那契数列:标签:__,generator,no,python,next,___,用法 From: https://blog.51cto.com/u_15858333/5817789
def f():
a,b=1,1
while True:
yield a
a,b=b,a+b
a=f()
for i in range(10):
print(a.___next___(),' ')
AttributeError: 'generator' object has no attribute '___next___'
原因是在python 3.x中 generator(有yield关键字的函数则会被识别为generator函数)中的next变为__next__了,next才是python 2.x的用法
2.x用法:
a.next()
3.x用法:
a.__next()__