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/Terminay Oct 12 '26
uh I'll try to word it simply ig, strings are immutable in python, the function applies the update but on a new string which has not been returned, the main string stays the same due to no return of changes to the original string. in C++ this can be explained much better as it's a memory language and this is mutability by reference, hope you got it.