It's definitely not the same. Similarly for a class you can define the __add__ dunder method for a + b and separately the __iadd__ dunder method for a += b. The first creates a new object, the latter changes/mutates the existing object a. For immutable types it is the same though.
bterwijn
Nice one, see the "Solution" link for correct answer.
Yes I understand your point, but I'm trying to reach out so people are aware and can use it in Python education. I feel it can really help beginners understand tricky concepts with ease, bit it's hard to reach a bigger audience these days. Sorry for the repetition, I'll guess I should cut back a bit.
Incorrect sorry, check the "Solution" link for the correct answer.
__add__ is called with + and __iadd__ is called with +=, and there is a difference: https://www.reddit.com/r/PythonLearning/comments/1nw08wu/right_mental_model_for_python_data/
C is incorrect,sorry. See the "Solution" link for the correct answer.
Actually running the code? I got to the stage where only AI can help me understand anything ;-)
Thanks for your feedback, much appriciated.
I agree that an exercise14.rst would be nice, but to save time I've let the code speak for itself now together with the visualizaion. I'll probably revisit and better document the exercises later.
At the Explanation link I try to give a general explanation about Pyrhon mutability (and copy later on), I agree some readers might find it hard relate that to a specific exercise, but I don't want to write a specific explanation for each exercise.
Thanks for report, should be fixed now.
You can just write your code and then press "Get URL" to get the link: https://memory-graph.com/#code=def+fun%28a+%3D+%5B%5D%29%3A%0A++++a+%2B%3D+%5B1%5D%0A++++return+a%0A%0Afun%28%29%0Aprint%28fun%28%29%29+%23+%5B1%2C+1%5D
DuckDuckGo problem, thanks for reporting.
The "Solution" link gives the solution to the exercise, the "Explanation" link explains the Python data model concepts behind the exercise. If some parts are hard to understand let me know.
Copying a list with a million elements every time you make a small change is not fun. Sure, you can optimize a bit behind the scenes, but that still gives a lot of overhead.