r/PythonProjects2 • • 8d ago

Python Mutability and Local Variables

Post image

An exercise to help build the right mental model for Python data. - Solution - Explanation - More exercises

The “Solution” link uses memory_graph to visualize execution and reveals what’s actually happening.

10 Upvotes

29 comments sorted by

View all comments

1

u/Terminay 8d ago

It's D. Good tool. I think I could integrate it into my ML for learners library (leanpass) you could search it up, would be a cool addition!

1

u/Tronco08 5d ago

why does printing a print nothing, it's the only one i dont understand

1

u/Terminay 3d ago

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.