It won't (using your example explicitly) but in general what you've discovered is that:
- Variables hold values
- Some of those values are references to shared mutable objects.
Lists fall into the second category. There are ways to copy lists if you want distinct behaviour.
list2 = list1[:]
will perform a "shallow copy". If you have a list of lists, however, the nested lists are still shared references. There is copy.deepcopy
available to make a complete clone of something (including all its nested members).