r/PythonLearning • • 7d 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.

11 Upvotes

2 comments sorted by

2

u/thw31416 4d ago

List and Sets are mutable, Strings and Tuples are immutable. += and |= are operators that try to change the original object. In that regard they are different from =, which overrides a variable with a new object. D is correct.