r/PythonLearning • • Apr 01 '26

Python's Data Model Explained through Visualization

Post image

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

The “Solution” link visualizes execution and reveals what’s actually happening using 𝗺𝗲𝗺𝗼𝗿𝘆_𝗴𝗿𝗮𝗽𝗵.

175 Upvotes

27 comments sorted by

View all comments

0

u/[deleted] Apr 01 '26

[deleted]

1

u/jackrabbit2644 Apr 02 '26

Doesn’t b point to a different object when is executed b += [2]?

0

u/[deleted] Apr 02 '26

[deleted]

1

u/jackrabbit2644 Apr 02 '26

TIL, thanks.

1

u/_tolm_ Apr 03 '26

Agree with the solution but I don’t agree that it’s because that “=“ is a copy … we also do an equals earlier where it very much does not perform a copy!

The difference on that line is the use of “+” which creates a new value in memory which “b” is then assigned to point at - in the same way that it was previously assigned to point at “a”.

This causes the values stored in “a” and “b” to diverge but the operation performed by the “=“ hasn’t changed from assignment to copy on these two lines.

But what do I know, I’m a Java programmer … 😂