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

John Salerno johnjsal at
Wed Apr 23 02:14:13 CEST 2008

Steve Holden wrote:

> Assignment to a list *element* rebinds the single element to the 
> assigned value. 

Ok, I understand that.

Assignment to a list *slice* has to be of a list [or iterable, as per 
Duncan], and it
> replaces the elements in the slice by assigned elements.

I don't understand the second part of that sentence. I'm assuming "it" 
refers to the list being assigned, "replaces the elements" is 
self-evident, but what does "by assigned elements" refer to? It seems 
when you assign a list to a list slice, nothing gets replaced, the slice 
just gets deleted.

More information about the Python-list mailing list