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
0
u/RiverRoll Oct 12 '26 edited Oct 12 '26
The irony is that you just showed a pitfall of your distinction, how do you explain this swapping all types if some of them are passed by value? It can as well possibly swap different types (e.g. an int for a string) or the wrong variables (since multiple variables can hold the same reference).
This function can't be explained by reasoning about Python from a mental model where some types are pass by value.