Why was p[:] designed to work differently in these two situations?
问题 p = [1,2,3] print(p) # [1, 2, 3] q=p[:] # supposed to do a shallow copy q[0]=11 print(q) #[11, 2, 3] print(p) #[1, 2, 3] # above confirms that q is not p, and is a distinct copy del p[:] # why is this not creating a copy and deleting that copy ? print(p) # [] Above confirms p[:] doesnt work the same way in these 2 situations. Isn't it ? Considering that in the following code, I expect to be working directly with p and not a copy of p , p[0] = 111 p[1:3] = [222, 333] print(p) # [111, 222, 333]