I'm total beginner to Python, so please could you explain me why the following situation happens. Consider the following code:
>>> A = [1, 2, 3, 4]
>>> B = A[0:2]
>>> print id(A) == id(B)
False
>>> print id(A[0]) == id(B[0])
True #Why?
>>> A[0] = 9
>>> A
[9, 2, 3, 4]
>>> B
[1, 2]
>>> print id(A[0]) == id(B[0])
False #Contradiction?
As you can see from the code above, I slice the list A and copy it to B, but, why print id(A[0]) == id(B[0])
evalutes True
on the first one but the opposite when I change either of A or B's value?