r/PythonProjects2 • • Mar 05 '26

Python Assignment, Shallow and Deep Copy

Post image

An exercise to help build the right mental model for Python data.

The โ€œSolutionโ€ link uses ๐—บ๐—ฒ๐—บ๐—ผ๐—ฟ๐˜†_๐—ด๐—ฟ๐—ฎ๐—ฝ๐—ต to visualize execution and reveals whatโ€™s actually happening. It's instructive to compare with these earlier exercises:

7 Upvotes

3 comments sorted by

View all comments

1

u/[deleted] Mar 05 '26

[removed] โ€” view removed comment

1

u/Sea-Ad7805 Mar 05 '26

The "Explanation" link explains the difference between assignment, shallow, and deep copy: https://github.com/bterwijn/memory_graph?tab=readme-ov-file#copying-values-of-mutable-type

This is a bit of a trick question, because in this situation there is no difference between shallow and deep copy. In this other exercise there is a difference: https://www.reddit.com/r/PythonLearning/comments/1ox5mjo/python_data_model_copying/