I'm learning Python and just came across the following behaviour.
I define a list x and assign (what I think is) the values of x to the variable y.
>>> x = [1,2,3]
>>> y = x
>>> y.extend([4,5,6])
>>> print y
[1, 2, 3, 4, 5, 6]
>>> print x
[1, 2, 3, 4, 5, 6]
But after extend'ing the list y, both x and y has the extra three elements. The same goes for append.
>>> x = [1,2]
>>> y = x
>>> y.append(3)
>>> print y
[1, 2, 3]
>>> print x
[1, 2, 3]
I understood the assign operator = as assigning from right to left, what am I not getting?
How can I assign a list from a named list but still be able to alter the new list without affecting the old one? Or is this not the right way to handle lists in Python?