explain slice assignment to newb

Sean DiZazzo half.italian at gmail.com
Sat Sep 20 23:25:39 CEST 2008


On Sep 20, 2:20 pm, Andrew <aet... at gmail.com> wrote:
> please explain this behavior to a newb:
>
> >>> a = [1,2,3,4]
> >>> b = ["a","b","c","d"]
> >>> a
> [1, 2, 3, 4]
> >>> b
>
> ['a', 'b', 'c', 'd']
>
> >>> a[0:2]
> [1, 2]
> >>> a
> [1, 2, 3, 4]
> >>> b[2:4]
> ['c', 'd']
> >>> a[0:2] = b[0:2]
> >>> b[2:4] = a[2:4]
> >>> a
> ['a', 'b', 3, 4]
> >>> b
> ['a', 'b', 3, 4]

What else would you expect to happen?



More information about the Python-list mailing list