Guys I'm trying to print the first 8 elements of the Fibonacci sequence and just want to understand one piece of code. When performing an assignment operation in a single line (n1,n2 = n2, n1+ n2) the code works fine, but when splitting the same assignment operation into separete lines like (n2 = n1+n2 and n1=n2), I get different results and code doesn't work in a way it supposed to, please explain me why?
def generate_fibonacci():
n1 = 0
n2 = 1
while True:
yield n1
n1,n2 = n2, n1+ n2 // this piece of code doesn't work properly when separating it
# n2 = n1 + n2
# n1 = n2
seq = generate_fibonacci()
for i in range(8):
print(next(seq))