This question already has an answer here:
- What does the “yield” keyword do? 40 answers
Can someone explain what each step in this does?
I have never seen "for i in X:" used where X is a generator, and I am failing to understand how the i interacts with the function if it's not being inserted between the ().
def fib():
a, b = 0,1
while True:
yield b
a,b = b, a + b
for i in fib():
print(i)