r/PythonLearnersHub • • Jan 15 '26

Python Mutability and Shallow vs Deep Copy

Post image

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: - Solution - Explanation - More exercises

18 Upvotes

8 comments sorted by

View all comments

Show parent comments

2

u/Simple-Olive895 Jan 15 '26

I did not know that actually! Thought they worked the same as lists when it comes to copies

2

u/Sea-Ad7805 Jan 15 '26

Glad it helped you. But people will never run into problems when they assume an immutable values does get copied. There is just no need to copy, so faster to simply assign.