Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: What is a function parameter =[] for? Date: Thu, 19 Nov 2015 11:14:49 +1100 Lines: 38 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de FxfRMs2K3Bnyi7SrMVO/SAzd34SyPdm1HO5mIHj0OoHA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'received:209.85.223': 0.03; 'cc:addr:python-list': 0.09; 'python.': 0.11; 'def': 0.13; 'wed,': 0.15; 'thu,': 0.15; 'cc:name:python': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'function?': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; '>>>': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'ctypes': 0.22; 'either.': 0.22; 'object.': 0.22; 'am,': 0.23; 'code,': 0.23; 'bit': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'chris': 0.26; 'right.': 0.27; 'message-id:@mail.gmail.com': 0.27; "people's": 0.29; 'raise': 0.29; 'certain': 0.31; 'source': 0.33; "i'll": 0.33; 'received:google.com': 0.35; 'so,': 0.35; 'skip:c 30': 0.35; 'nov': 0.35; 'received:209.85': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'no,': 0.38; 'received:209': 0.38; 'some': 0.40; 'default': 0.61; '11:02': 0.84; 'chrisa': 0.84; 'hmm...': 0.84; 'to:none': 0.91; 'played': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=hII2xmMfqDwcQcNQIctMzGClEciH4l4clcnzjuld7sU=; b=g+19YE9RuDLmGyqwTuvlTBdBgsTgnKa5sqESKMTJHnZtJzaLQ3VPGu//+o7g/QJhgE rsvmTuL64IenXwNYz/jQD19may6h+hF+nrVMlmrsf/aej1v9HnFmxl4N724KyNAYXJPG VkNoDnhWsBHPTTd6pUxHl2YhAxNpQgw+NI/uxGbuiqf9K6jGPTuOg6MwcR3Gnvd15nwm /CnAmMdn5/pebnV1C7OQunpxL0GLacWQJTem8YBdL23y77um2LfjjYWHxKrGVEV5ndHp OlNvfVRn0ziAoKAc8pCjKcNL86N+AQ4TKLNoj5D5qbyfGZ7dzljFWOkbqVkJcctkdfMv wBAQ== X-Received: by 10.107.3.163 with SMTP id e35mr5337502ioi.157.1447892089818; Wed, 18 Nov 2015 16:14:49 -0800 (PST) In-Reply-To: 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: , Xref: csiph.com comp.lang.python:99018 On Thu, Nov 19, 2015 at 11:02 AM, Ian Kelly wrote: > On Wed, Nov 18, 2015 at 4:22 PM, Chris Angelico wrote: >> On Thu, Nov 19, 2015 at 10:14 AM, BartC wrote: >>> So, looking at some source code, a default value for certain types is only >>> certain to be that value for the very first call of that function? >> >> On the contrary, it is certain always to be that exact object. > > "Certain" may be a bit overly strong. > >>>> def f(x=42): > ... return x > ... >>>> f() > 42 >>>> f.__defaults__ = (43,) >>>> f() > 43 I'll raise you one. >>> def f(x=42): ... return x ... >>> f() 42 >>> import ctypes >>> ctypes.c_int.from_address(id(43)+ ctypes.sizeof(ctypes.c_size_t) + ctypes.sizeof(ctypes.c_voidp)).value=42 >>> f.__defaults__ = (43,) >>> f() 42 >>> Nothing is certain in Python. And two wrongs can make a... hmm... no, this is not a right. It is not a privilege either. It is a dastardly trick played on people's minds. ChrisA