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


Groups > comp.lang.python > #6298

Re: Puzzled by list-appending behavior

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <chris@rebertia.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'wed,': 0.03; '*not*': 0.05; 'interpreter': 0.07; 'convention,': 0.09; 'indicates': 0.09; 'modifies': 0.09; 'none.': 0.09; 'shortcut': 0.09; 'pm,': 0.10; 'output': 0.11; '25,': 0.12; 'wrote:': 0.14; 'expected.': 0.16; 'received:209.85.213.174': 0.16; 'received:mail- yx0-f174.google.com': 0.16; 'reinforce': 0.16; 'subject:behavior': 0.16; 'to:name:uncle ben': 0.16; 'cc:addr:python-list': 0.17; 'subject:list': 0.19; 'uncle': 0.19; 'cheers,': 0.19; 'header:In- Reply-To:1': 0.21; 'say,': 0.22; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'similarly': 0.23; '(in': 0.26; 'object': 0.26; 'message-id:@mail.gmail.com': 0.28; '(the': 0.28; 'lists': 0.29; 'cc:addr:python.org': 0.30; 'expression': 0.32; 'someone': 0.33; 'does': 0.33; 'me?': 0.33; 'list': 0.33; 'list.': 0.33; 'rather': 0.34; 'chris': 0.34; 'languages': 0.35; 'lists,': 0.36; 'none': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.37; 'playing': 0.37; 'received:209.85.213': 0.37; 'but': 0.38; 'subject:: ': 0.38; 'explain': 0.39; 'user': 0.39; 'received:209': 0.39; 'returned': 0.39; 'following:': 0.40; 'skip:\xc2 10': 0.72; 'with,': 0.77; '3.1,': 0.84; 'sender:addr:chris': 0.84; 'contrast': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=I+sxKpXMJz+1/Nks+Sb7E3sQVgH7pM2utwze2ZP6FLA=; b=YPR1oPSEgA+Z9Js4Ctu+Z2asg2UzlzrH/Lcx5eb7kf6xK4lzwrAHhYg6Xx0nL4kPlA 2cu9DT356wOfegPLTF32xZ0AyKKp7I4ou7hRmiJZLKhJaOkNBCNXipTEitBYG5lwhd3Q B6F+J1fqUx8nix8whFCziiXJ8y24SrZiyW34Q=
DomainKey-Signature a=rsa-sha1; c=nofws; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=IVr70Mrr7jKvS7hZ5XAKODtUF20Dg1H7/jdPRZxoOF59QcGVukLY9Y17REGSxHpvk2 GLw0uvHpIKBM//d24LoXdWI7BAn2Oa7kNb4RzU2jc71VI2h0h/6cHRlly9GrU/YeYBqm SDirpZsZ6xkGVC9XsNveK0dTuwt6biciDxmho=
MIME-Version 1.0
Sender chris@rebertia.com
In-Reply-To <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com>
References <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com>
Date Wed, 25 May 2011 22:17:45 -0700
X-Google-Sender-Auth UTZNgXsCaBMejGRDotNw8-HoKT4
Subject Re: Puzzled by list-appending behavior
From Chris Rebert <clp2@rebertia.com>
To Uncle Ben <bgreen@nycap.rr.com>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2108.1306387068.9059.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 82.94.164.166
X-Trace 1306387068 news.xs4all.nl 49179 [::ffff:82.94.164.166]:36439
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6298

Show key headers only | View raw


On Wed, May 25, 2011 at 9:46 PM, Uncle Ben <bgreen@nycap.rr.com> wrote:
> In playing with lists of lists, I found the following:
>
> (In 3.1, but the same happens also in 2.7)
>
> list = [1,2,3]
> list.append ( [4,5,6] )

Note the lack of output after this line. This indicates that
list.append([4,5,6]) returned None. Contrast this with, say,
list.pop().

> x = list
> x   ->
>    [1,2,3,[4,5,6]]
> as expected.
>
> But the shortcut fails:
>
> list=[1,2,3]
> x = list.append( [4,5,6] )
> x   ->
>   nothing
>
> Can someone explain this to me?

The append() method does *not* return the now-appended-to list. It is
a mutator method that modifies the list object in-place; per
convention, it therefore returns None to reinforce its side-effecting
nature to the user (the interactive interpreter by default does not
display None expression results); analogous methods in other languages
return void.

list.remove(), list.sort(), and list.extend() similarly return None
rather than the now-modified list.

Cheers,
Chris
--
http://rebertia.com

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


Thread

Puzzled by list-appending behavior Uncle Ben <bgreen@nycap.rr.com> - 2011-05-25 21:46 -0700
  Re: Puzzled by list-appending behavior Ben Finney <ben+python@benfinney.id.au> - 2011-05-26 15:11 +1000
  Re: Puzzled by list-appending behavior Chris Rebert <clp2@rebertia.com> - 2011-05-25 22:17 -0700
  Re: Puzzled by list-appending behavior Chris Angelico <rosuav@gmail.com> - 2011-05-26 17:20 +1000
  Re: Puzzled by list-appending behavior Chris Angelico <rosuav@gmail.com> - 2011-05-26 17:23 +1000
  Re: Puzzled by list-appending behavior Uncle Ben <bgreen@nycap.rr.com> - 2011-05-26 00:33 -0700
  Re: Puzzled by list-appending behavior Chris Rebert <clp2@rebertia.com> - 2011-05-26 01:09 -0700
  Re: Puzzled by list-appending behavior MRAB <python@mrabarnett.plus.com> - 2011-05-26 16:58 +0100
    Re: Puzzled by list-appending behavior Tim Roberts <timr@probo.com> - 2011-05-26 23:34 -0700
      Re: Puzzled by list-appending behavior MRAB <python@mrabarnett.plus.com> - 2011-05-27 17:02 +0100
  Re: Puzzled by list-appending behavior Chris Angelico <rosuav@gmail.com> - 2011-05-27 02:04 +1000
  Re: Puzzled by list-appending behavior John Ladasky <ladasky@my-deja.com> - 2011-05-26 11:27 -0700
    Re: Puzzled by list-appending behavior Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-27 01:59 +0000
      Re: Puzzled by list-appending behavior Chris Angelico <rosuav@gmail.com> - 2011-05-27 13:24 +1000
        Re: Puzzled by list-appending behavior Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-27 03:52 +0000
          Re: Puzzled by list-appending behavior Chris Angelico <rosuav@gmail.com> - 2011-05-27 14:10 +1000
          RE: Puzzled by list-appending behavior "Prasad, Ramit" <ramit.prasad@jpmchase.com> - 2011-05-27 13:58 -0400
          Re: Puzzled by list-appending behavior Ethan Furman <ethan@stoneleaf.us> - 2011-05-27 11:56 -0700
  Re: Puzzled by list-appending behavior Terry Reedy <tjreedy@udel.edu> - 2011-05-26 14:44 -0400
  RE: Puzzled by list-appending behavior "Prasad, Ramit" <ramit.prasad@jpmchase.com> - 2011-05-26 15:34 -0400
  Re: Puzzled by list-appending behavior Terry Reedy <tjreedy@udel.edu> - 2011-05-26 17:36 -0400

csiph-web