Can someone explain how the increment of a
or value of a
occurs within the for loop to generate the Fib sequence?
I have an understanding of (a, b = b, a + b). However, I am unable to figure how the increment occurs in the for loop when next() is called.
def fib(n):
a, b = 0, 1
for _ in range(n):
yield a
a, b = b, a + b
x = fib(4)
print(x.__next__())
print(x.__next__())
print(x.__next__())
print(x.__next__())
0 1 1 2