In Python (2 and 3). Whenever we use list slicing it returns a new object, e.g.:
l1 = [1,2,3,4]
print(id(l1))
l2 = l1[:]
print(id(l2))
Output
>>> 140344378384464
>>> 140344378387272
If the same thing is repeated with tuple, the same object is returned, e.g.:
t1 = (1,2,3,4)
t2 = t1[:]
print(id(t1))
print(id(t2))
Output
>>> 140344379214896
>>> 140344379214896
It would be great if someone can shed some light on why this is happening, throughout my Python experience I was under the impression empty slice returns a new object.
My understanding is that it's returning the same object as tuples are immutable and there's no point of creating a new copy of it. But again, it's not mentioned in the documents anywhere.