Let's start with a list a
:
>>> a = [1,2,3]
>>> id(a)
4511772616
I know we can use a[:]
to create a copy of a:
>>> id(a[:])
4511794120
However, my question is: Why I can use a[:]
to reassigns all of the contents of a without changing the address of it?
>>> a[:] = [1,2,3]
>>> id(a)
4511772616
>>> a
[1,2,3]
Also, if I wanna go deep to figure out what's under the hood, where should I start with? I tried to find some memory management materials about Python. However, it seems that they all rarely talk about the case of special syntax such as List comprehension and Slicing notation.