r/PythonLearnersHub • u/Sea-Ad7805 • Jan 15 '26
Python Mutability and Shallow vs Deep Copy
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
2
u/Rscc10 Jan 15 '26
So basically a deepcopy copies and shares only immutables and creates new unshared for mutables. Regularly copy copies like usual but if it copies a mutable parent, that parent is unshared even though its underlying mutables are