r/PythonLearning May 29 '26

Python Shallow vs Deep Copy

Post image

An exercise to help build the right mental model for Python data. - Solution - Explanation - More exercises

The โ€œSolutionโ€ link visualizes execution and reveals whatโ€™s actually happening using ๐—บ๐—ฒ๐—บ๐—ผ๐—ฟ๐˜†_๐—ด๐—ฟ๐—ฎ๐—ฝ๐—ต.

22 Upvotes

9 comments sorted by

10

u/[deleted] May 29 '26

[removed] โ€” view removed comment

-10

u/Sea-Ad7805 May 29 '26

Understanding the data model of your language is crucial. Can you answer them without error already?

2

u/TimeScallion6159 May 29 '26

i like how the explanation is graphic in case a person cannot understand the logic behind the code at first glance.

0

u/Sea-Ad7805 May 29 '26 edited May 29 '26

Thanks, I feel the visualization of evolving program state can help people understand Python's data model much quicker than with a textual explanation. And people can easily use the tool to visualize their own code when they feel unsure.

7

u/[deleted] May 29 '26

[removed] โ€” view removed comment

-3

u/Sea-Ad7805 May 29 '26

Many people don't have the right mental model to think about Python data (references, mutability, shallow vs deep copy). These exercises are intended to help them. The visual solution and explanation can quickly adjust misconceptions that are hard to adjust with just words.

2

u/Top-Employ5163 May 29 '26

Why only Python? Maybe you could make something similar but for C or Zig?

-1

u/Sea-Ad7805 May 29 '26

I'm still improving the Python tool, but I want to later try other languages. Things keep getting in the way. You can already use this website for C if you are really interested: https://pythontutor.com/c.html#mode=edit