Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90622
| 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 | <billy.earney@gmail.com> |
| 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 <billy.earney@gmail.com> |
| To | "python-list@python.org" <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 <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.11.1431626772.17265.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
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
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
a python pitfall Billy Earney <billy.earney@gmail.com> - 2015-05-14 13:06 -0500 Re: a python pitfall Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-15 12:03 +1000
csiph-web