explain slice assignment to newb

Andrew aetodd at gmail.com
Sat Sep 20 23:20:20 CEST 2008


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]
>>>




More information about the Python-list mailing list