Lists: why is this behavior different for index and slice assignments?

Michael Torrie torriem at
Tue Apr 22 04:10:03 CEST 2008

John Salerno wrote:
> So the question is, when you assign an empty list to an index, why does 
> it insert an empty list, but when you assign an empty list to a slice, 
> it simply deletes the slice?

I would say this is consistent behavior because a list slice is also a
list itself.  Whereas a list element is just that.  A reference to an
object that can be rebound.  In the latter case you are rebinding a
single list item to an empty list.

More information about the Python-list mailing list