def fib(max):
n, a, b = 0, 0, 1
while n < max:
yield b
a, b = b, a + b
n = n + 1
return 'done'
print(next(fib(6)))
print(next(fib(6)))
print(next(fib(6)))
the result is 1,1,1
.
However, if I change the content in print()
as below:
f = fib(6)
print(next(f))
print(next(f))
print(next(f))
the result will be 1, 1, 2
. Why does this happen?