Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'wed,': 0.03; '*not*': 0.05; 'interpreter': 0.07; 'convention,': 0.09; 'from:addr:python': 0.09; 'indicates': 0.09; 'modifies': 0.09; 'none.': 0.09; 'rule.': 0.09; 'shortcut': 0.09; 'pm,': 0.10; 'output': 0.11; '25,': 0.12; 'wrote:': 0.14; 'expected.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'rebert': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reinforce': 0.16; 'reply-to:addr :python-list': 0.16; 'subject:behavior': 0.16; 'subject:list': 0.19; 'uncle': 0.19; 'header:In-Reply-To:1': 0.21; 'say,': 0.22; 'similarly': 0.23; 'received:84': 0.25; 'skip:[ 10': 0.26; '(in': 0.26; 'object': 0.26; '(the': 0.28; 'lists': 0.29; 'expression': 0.32; 'someone': 0.33; 'does': 0.33; 'to:addr:python-list': 0.33; 'me?': 0.33; 'list': 0.33; 'list.': 0.33; 'rather': 0.34; 'chris': 0.34; 'example,': 0.35; 'header:User-Agent:1': 0.35; 'reply- to:addr:python.org': 0.35; 'languages': 0.35; 'lists,': 0.36; 'none': 0.37; 'playing': 0.37; 'but': 0.38; 'subject:: ': 0.38; 'explain': 0.39; 'sometimes': 0.39; 'user': 0.39; "i'd": 0.39; 'returned': 0.39; 'to:addr:python.org': 0.39; 'following:': 0.40; 'header:Reply-To:1': 0.72; 'reply-to:no real name:2**0': 0.72; 'with,': 0.77; '3.1,': 0.84; 'contrast': 0.91 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsgHAGx43k1UXebj/2dsb2JhbABVhEmTXY4KeLYskFOBK4NqgQcElHKKWA Date: Thu, 26 May 2011 16:58:25 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Puzzled by list-appending behavior References: <16c21256-48df-416a-971f-de49ca4cc981@x6g2000yqj.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 39 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1306425500 news.xs4all.nl 49039 [::ffff:82.94.164.166]:33986 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6324 On 26/05/2011 06:17, Chris Rebert wrote: > On Wed, May 25, 2011 at 9:46 PM, Uncle Ben 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. > I'd just like to point out that it's a convention, not a rigid rule. Sometimes it's not followed, for example, dict.setdefault.