Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!news.roellig-ltd.de!open-news-network.org!cyclone03.ams2.highwinds-media.com!news.highwinds-media.com!voer-me.highwinds-media.com!lightspeed.eweka.nl!lightspeed.eweka.nl!newsfeed.xs4all.nl!newsfeed4a.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.061 X-Spam-Evidence: '*H*': 0.89; '*S*': 0.01; 'output': 0.05; '[1,': 0.09; 'python:': 0.09; 'def': 0.12; 'subject:python': 0.16; 'example': 0.22; 'to:name:python-list@python.org': 0.22; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'thanks!': 0.32; 'received:google.com': 0.35; 'skip:& 10': 0.38; 'to:addr :python-list': 0.38; 'expect': 0.39; 'to:addr:python.org': 0.39; 'believe': 0.68; 'url:me': 0.69; 'saw': 0.77; 'zen': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=Cu5O8+ozdMSqJ+gRvOrbIi63fJtlTWGbnuI0SBkNr2Y=; b=pZzIy0cCPcYlvCUsF5ykkpOkFH+RzqiryXV4no6qAOf4+cJ4izcnw/0VgUrKnV6L12 9YqNeAaJONegDjAEvg7LXAnUvdutN9gL6CCbduSlWf8n5grFvZExqpBRnX2g4c8caDFX oilkg8jFXy65Rqf+RI4/FBSlCkpelgZ/RqSWGKqxO/Hv7XqsKDnwUvJcemXWbTdU9P/c QIHbD9ys7GxehedZdIsqSyrim5hKY+JqmDKRYzAn2uaQSc7mNKXD9PqVmsSCzBFdZ+qw BTtbVX2Gx5Sh7V/Hx1kAU6lFwId/mH1RMVLow6gM0MD/VCKYhExxLSyRd9nqUjgPGJ/j QvPg== MIME-Version: 1.0 X-Received: by 10.152.43.74 with SMTP id u10mr4098605lal.90.1431626769268; Thu, 14 May 2015 11:06:09 -0700 (PDT) Date: Thu, 14 May 2015 13:06:09 -0500 Subject: a python pitfall From: Billy Earney To: "python-list@python.org" Content-Type: multipart/alternative; boundary=001a11c34cd808847005160e95c4 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list 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: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1431626772 news.xs4all.nl 2963 [2001:888:2000:d::a6]:41679 X-Complaints-To: abuse@xs4all.nl X-Received-Body-CRC: 1593599563 X-Received-Bytes: 4439 Xref: csiph.com comp.lang.python:90622 --001a11c34cd808847005160e95c4 Content-Type: text/plain; charset=UTF-8 Hello friends: I saw the following example at http://nafiulis.me/potential-pythonic-pitfalls.html#using-mutable-default-arguments and did not believe the output produced and had to try it for myself.... def foo(a,b,c=[]): c.append(a) c.append(b) print(c) foo(1,1) foo(1,1) foo(1,1) produces: [1, 1] [1, 1, 1, 1] [1, 1, 1, 1, 1, 1] One would expect the following output: [1, 1] [1, 1] [1, 1] Doesn't this valid the zen of python: "Explicit is better than implicit." ? Thanks! Billy --001a11c34cd808847005160e95c4 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hello friends:

I saw the followin= g example at=C2=A0http://nafiulis.me/potential-pythoni= c-pitfalls.html#using-mutable-default-arguments=C2=A0and did not believ= e the output produced and had to try it for myself....

<= div>def foo(a,b,c=3D[]):
=C2=A0 =C2=A0 c.append(a)
=C2= =A0 =C2=A0 c.append(b)
=C2=A0 =C2=A0 print(c)

foo(1,1)
foo(1,1)
foo(1,1)

produces:
[1, 1]
[1, 1, 1, 1]
[1, 1, = 1, 1, 1, 1]

One would expect the following o= utput:
[1, 1]
[1, 1]
[1, 1]

Doesn't this valid the zen of python: "Explicit = is better than implicit." =C2=A0?

Thanks!
Billy
--001a11c34cd808847005160e95c4--