I've decided to try and learn Python. I'm using the tutorial in the documentation and there's something I don't quite understand.
When using slice notation, it looks like I am sometimes getting a copy of the object and other times I get the object itself. Sounds vague, I know, but the following example shows what I mean.
If I write the following in the python shell:
a = [1, 2, 3]
a[:] = [4, 5, 6]
a
the output is: [4, 5, 6], so the object 'a' was modified, but if I write the following:
a[:].append(7)
a
the output is: [4, 5, 6], so 'a' was not modified, which I assume is because append() was called on a copy of 'a' returned by the [:].
So what's going on?
Another question: Why does Python allow me to write the second code snippet? I mean, modifying a temporary copy of 'a' doesn't make sense, so shouldn't this be flagged as an error (like it does in C++)?
Thanks in advance.