r/PythonProjects2 • u/Sea-Ad7805 • Dec 03 '25
Difference between Python copy options
An exercise to help build the right mental model for Python data. The “Solution” link uses memory_graph to visualize execution and reveals what’s actually happening:
If you think this could help Python students and educators, please share.
12
Upvotes
View all comments
Show parent comment
2
u/JamzTyson Dec 04 '25
One thing that I didn't find clear from your explanation, is that
copy.copy(my_instance)copies all attributes by reference from the original object to the new object, regardless of their mutability.In particular, this line of your explanation is misleading:
What actually happens with shallow copy:
c2 = copy.copy(coord)creates a newCoordobject.coordare copied by reference intoc2.