|
|
|
|
|
by triMichael
2744 days ago
|
|
I think I can answer this one because it is one of my gripes of Python. The problem isn't that it doesn't copy, rather it is that the = assignment operator specifically doesn't copy. If you create a list "list1", set "list2 = list1", and change list1, both of the lists change. When I learned Python, this was a major source of confusion for me. Eventually I learned that in Python, instead of nothing being a pointer as it first appears, it is actually that everything is a pointer. On the other hand, while the same things occur in C++, the assignment operator does a shallow copy and anytime you are doing a pointer copy it is explicit. |
|
Ned Batchelder is a good resource for learning many things about python, and this talk he gave at Pycon some years ago is no exception:
https://nedbatchelder.com/text/names1.html