The Nile

On the freeform project “The Nile” from “Learn Python 3”, we are asked to unpack the tuple on step 2.
I noticed that the unpacking must be written this way:

from_lat, from_long = from_coords
to_lat, to_long = to_coords

and not this way:

from_coords = from_lat, from_long
to_coords= to_lat, to_long

Can anyone explain why that is?!?

Merci beaucoup!

Consider how the assignment operator works. If we have the following:

a = 1
b = 2

a = b #what happens here?
print(f'a: {a}; b: {b}')


a: 2; b: 2

Assignment when unpacking a tuple happens in the same direction.

The value(s) on the right are assigned to the variable(s) on the left. Nothing really special or unique.

Tuples are immutable and make great persistent read only objects. What’s more, since Python variables can be re-used we can create new tuples from old and assign them back to the same variable.

When unpacking, we need to be informed of what the meaning attached to each value in the tuple actually is. Furthermore, the left-hand side of the assignment must correspond to the number of values in the sequence on the right.

>>> z =  1, 2, 3, 4, 5, 6, 7
>>> a, b, c = z
Traceback (most recent call last):
  File "<pyshell#38>", line 1, in <module>
    a, b, c = z
ValueError: too many values to unpack (expected 3)