Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25027

Re: something go wrongly

References <CAEMsKDvn8cm+_VBB+inyFZpSNgCMK+g7k3BCwn0LFw4i_YtzyQ@mail.gmail.com>
Date 2012-07-07 10:35 -0700
Subject Re: something go wrongly
From Chris Rebert <clp2@rebertia.com>
Newsgroups comp.lang.python
Message-ID <mailman.1897.1341682558.4697.python-list@python.org> (permalink)

Show all headers | View raw


On Sat, Jul 7, 2012 at 10:23 AM, levi nie <levinie001@gmail.com> wrote:
> my code:
>
> aList=[1,2,3,4,5,6,7,8,9,10]
> xList=[1,2,3]
> print "now aList is",aList.extend(xList)
>
> output:
> now aList is None
>
> what i want is [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3]

See http://stackoverflow.com/a/1682601
list.extend(), list.append(), etc. operate in-place, mutating the
existing list object. Such methods return None to emphasize that they
do not create new lists.

Regards,
Chris

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: something go wrongly Chris Rebert <clp2@rebertia.com> - 2012-07-07 10:35 -0700

csiph-web