[Tutor] s[len(s):len(s)] = [x] ??

John Fouhy john at fouhy.net
Mon Jun 30 00:39:58 CEST 2008


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

-- 
John.


More information about the Tutor mailing list