Today, due to a weird behavior in an application's functionality, I discovered this strange behavior of Python assignment operator which I was completely oblivious to.
As per my understanding, '=' operator is meant to assign values to variables.
So I tried this:
>>> x = 5 --> assigned integer 5 to x
>>> y = x --> assigned value of 'x' (5) to y
>>> y = 6 --> assigned integer 6 to y
>>> x
5 --> x remains 5 (unchanged)
>>> y
6 --> y changes to 6 (as expected)
But then I tried the same thing with lists:
>>> x = [] --> assigned empty list to x
>>> y = x --> assigned value of 'x' (empty list) to y
>>>
>>> y.append({'id': 2}) --> updated value of y
>>>
>>> y
[{'id': 2}] --> y changes to new value (as expected)
>>>
>>> x
[{'id': 2}] --> x changes to new value (un-expected. How ???????)
Can someone explain why this difference in behavior?