I recently discovered that Python list assignment does not work quite the way I expected it to, as illustrated below:
>>> a = [1,2,3]
>>> b = a
>>> b.append(4)
>>> b
[1, 2, 3, 4]
>>> a
[1, 2, 3, 4]
>>>
I was expecting this to create a copy of "a", store it as "b", and then modify "b", leaving "a" unchanged. Python seems to behave this way with respect to any operation which modifies lists in place.
It's simple enough to work around this (by entering ">>> b=[x for x in a]", for example), but I'm still confused by it. Is this just a random quirk in Python, or am I failing to grasp something deeper about the way the language works?