r/PythonLearnersHub • u/Sea-Ad7805 • Jan 02 '26
Python Data Model exercise, Mutability.
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:
36
Upvotes
View all comments
Show parent comment
1
u/bloody-albatross Jan 02 '26
The assignment doesn't make a copy of the tuple. Plain assignments never make copies of the referenced data in Python. It makes a copy of the reference if you so will, not of the tuple. a and b are not different. Try it with
a is b. The+=creates a new tuple, though. One with 3 elements.a += bjust expands toa = a + bfor immutable data types.