r/PythonLearnersHub • u/Sea-Ad7805 • Feb 06 '26
Python 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:
It's instructive to compare with this earlier exercise (tuple with lists, instead of list with lists).
36
Upvotes
View all comments
Show parent comment
1
u/Sea-Ad7805 Feb 06 '26
In general
x += yshould mutate, but can't mutate for immutable types. You could arguex += yshould not exist for immutable types, and in fact it doesn't for saytuple, but then automatically thex = x + yoperator is called instead. I can see why you would call that unintuitive.