[Tutor] s[len(s):len(s)] = [x] ??
Dick Moores
rdm at rcblue.com
Mon Jun 30 04:16:52 CEST 2008
At 03:39 PM 6/29/2008, John Fouhy wrote:
>On 28/06/2008, Dick Moores <rdm at rcblue.com> wrote:
> > I'm very familiar with appending x to a list, s, using
> s.append(x), however,
> > I've never understood what the docs mean by
> >
> > s.append(x) same as s[len(s):len(s)] = [x]
>
>In addition to Douglas's comment, do you understand how assignment
>with slices works?
>
>e.g. can you predict the result of the following operations without trying it?
>
>a = [1, 2, 3, 4]
>a[1:3] = [7, 8]
>print a
[1, 7, 8, 4] Whew!
(I really wasn't positive that it shouldn't be [1, [7, 8], 4] !)
Dick
More information about the Tutor
mailing list