Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Antoon Pardon Newsgroups: comp.lang.python Subject: Re: What is a function parameter =[] for? Date: Tue, 24 Nov 2015 15:38:26 +0100 Lines: 30 Message-ID: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de tgoPQOVUyRevnAOmqDnitgAQ1I9XCN/itNZyAbYIfozQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; '*value*': 0.09; 'defined,': 0.09; 'mutable': 0.09; 'objects.': 0.09; 'talks': 0.11; 'syntax': 0.13; 'def': 0.13; 'argument': 0.15; '(barring': 0.16; '*expression*': 0.16; 'changes!': 0.16; 'evaluating': 0.16; 'former,': 0.16; 'grasp': 0.16; 'omitted.': 0.16; 'received:adsl- dyn.isp.belgacom.be': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; '2015': 0.20; 'changes,': 0.23; 'consistent': 0.23; 'header:In-Reply-To:1': 0.24; 'header :User-Agent:1': 0.26; "doesn't": 0.26; 'chris': 0.26; 'fri,': 0.27; 'function': 0.28; 'received:192.168.1.3': 0.29; 'objects': 0.29; 'tutorial': 0.29; 'received:be': 0.30; "can't": 0.32; 'values.': 0.33; 'that,': 0.34; 'nov': 0.35; "isn't": 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'wrong': 0.38; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'default': 0.61; 'here.': 0.62; 'charset:windows-1252': 0.62; 'face': 0.64; '20,': 0.66; 'virtually': 0.66; 'results': 0.66; 'talking': 0.67; 'angelico:': 0.84; 'received:195.238': 0.84; 'schreef': 0.84; 'acknowledge': 0.93; 'confirms': 0.95 X-Belgacom-Dynamic: yes X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2CWAQAzdVRW/9Xi9VENUYR9wRuDEIJ/AoF1EAEBAQEBAQGFPgEBAQMBeAYLCxgJFg8JAwIBAgFFEwYCAogVAwYEDa0xjCUMSIQmAQEIAgEghlSEfoUnhBIBBJZQiBaFG5xLOIQwcYUrAQEB User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.8.0 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:99344 Op 20-11-15 om 14:04 schreef Chris Angelico: > On Fri, Nov 20, 2015 at 11:39 PM, BartC wrote: >> * The refusal to acknowledge that the def fn(a=[]) syntax is misleading. >> (What value will a have when you call fn()? The true answer is that you >> can't tell.) > > It isn't misleading. The default value for the argument is set when > the function is defined, and it is set to the *object* that results > from evaluating the *expression* given. After that, the *object* is > the one you will always get (barring shenanigans) if the argument is > omitted. If the value of that object changes, it changes! That you can perfectly explain what happens, doesn't contradict that it is misleading. On the contrary, the fact that one needs all this explanation in order to grasp what is happening, confirms that it is misleading. And you may be talking about objects here. The tutorial talks about values. > You keep expecting the *value* to be consistent. But what you actually > get is that the *object* is consistent. It's virtually impossible to > guarantee the former, in the face of mutable objects. What is wrong with expecting the value to be consistent when the tutorial talks about values? -- Antoon.