Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news2.arglkargh.de!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.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.018 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'function:': 0.09; 'parameter': 0.09; 'def': 0.12; "wouldn't": 0.14; 'expecting': 0.16; 'foo()': 0.16; 'picks': 0.16; 'subject:parameters': 0.16; 'substituted': 0.16; 'value;': 0.16; 'wrote:': 0.18; 'thu,': 0.19; "haven't": 0.24; 'header:In-Reply-To:1': 0.27; 'message- id:@mail.gmail.com': 0.30; 'you?': 0.31; 'call.': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'expect': 0.39; 'to:addr:python.org': 0.39; 'back': 0.62; "you've": 0.63; 'different': 0.65; 'default': 0.69 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=hezTXbRlIaDLyNaBoKcPaPTXCkQk36YrBnmRRi+fRyY=; b=txxgIXJwcL+Gd6ZGyKFLGhfyEEgFj4FmeqV5oEluZSdbB8DzkYfb2tArt2ijniV42w ojlYbO/Ue5f+vLge+CmHGOdK8kp9h6wvFLGJKwUp4VqXMjdoPPI2usN/GfHKb4Hbph8W KXlmeZWn46o7jV9BxxkzxYWhMivimUAjRnnBviPryu91KQURacSh9W6zEGhYSd6rLEhd SGC1zbEDcOhn59b8C6otY0U+9oOYbkLpaLWgemmmzwJ9/kJCJVFThV56Cthybai5qbOp Vq3z0S5Fw15XqiYQx0rOYSgnxy2zoYberQnyNPOevm/T6G5ipnMk0P0AJqM7awo4UOrh t2JA== X-Received: by 10.68.110.165 with SMTP id ib5mr10321892pbb.61.1396560802220; Thu, 03 Apr 2014 14:33:22 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Thu, 3 Apr 2014 15:32:42 -0600 Subject: Re: Default mutable parameters in functions To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1396560805 news.xs4all.nl 2891 [2001:888:2000:d::a6]:40671 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69612 On Thu, Apr 3, 2014 at 12:49 PM, wrote: > Now call it with a value: > foo([ 3 ]) > > as you might expect: > It's a parrot, not a cheese: [3] > > But now go back to no parameter in the call: > foo() > foo() > foo() > > It's a parrot, not a cheese: [46] > It's a parrot, not a cheese: [47] > It's a parrot, not a cheese: [48] > > it picks up where it left off. > > I was rather expecting it to start with 4! You haven't replaced the default value; you've only substituted a different value for that call. In this function: def foo(x=3): print(x) You wouldn't expect a call of foo(27) to change the default value to 27, would you?