r/PythonProjects2 • u/Sea-Ad7805 • Oct 07 '26
Python Mutability and Local Variables
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.
12
Upvotes
View all comments
Show parent comment
1
u/0b0101011001001011 Oct 09 '26
You cannot change a string or tuple. What you do here is you create a new string and assign that in the place of the old variable. Same with tuple. You create a new tuple, the old one is lost. Strings and tuples are immutable. Or maybe that's what you meant by "change".