I'm quite new to Python and learning it on Lynda.com, which does not seem to have any way to ask questions about lesson content. In a video about while loops there is this code:a, b = 0, 1while b < 50:    print(b)    a, b = b, a + bthat results in: 1, 1, 2, 3, 5, 8, 13, 21, 34 . Out of curiosity, I changed the a, b = b, a + b parallel assignment to two separate simple assignments: a = bb = a + bbut that changes the result to: 1, 2, 4, 8, 16, 32 My question is - aside from the format, how are these statements different? Why is the result different?
Parallel vs Simple Assignment question
python;coding standards;programming logic
Suppose a is 3 and b is 5.Then:a, b = b, a + bwill do the same thing as:a, b = 5, 3 + 5or:a, b = 5, 8i.e. it sets a to 5 and b to 8.When you have two separate statements:a = bb = a + bthey run in sequence.First this runs:a = band now a is 5.Then this runs:b = a + band now b is 5 + 5, or 10. The end result is that a is 5 and b is 10, instead of 8.