# Attempt1 using direct index-based assignment
p=[1,2,3,4]
p[1]=p[2]=[]
print(p) # [1, [], [], 4]
// that sounds reasonable..
# Attempt2 using slice-based assignment
p=[1,2,3,4]
print(p[1:3]) # [2, 3]
p[1:3]=[]
print(p) # [1, 4] !!
In my understanding after reading the answers from here, p[1:3] is supposed to be a sequence of references on which the assignment to an empty list is supposed to happen. But it seems to remove the elements from the list ! Almost as if, I did this:
p=[1,2,3,4]
print(p) # [1, 2, 3, 4]
del p[1:3]
print(p) # [1, 4]
Can you explain this ?