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:24:55 +0100 Lines: 42 Message-ID: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de IbSd4ywTc5U7uq+x7ePOlgaAulKkNsi97vSXNoNiHzAA== 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; '(even': 0.05; 'constructor': 0.07; 'behave': 0.09; 'brackets': 0.09; 'differently.': 0.09; 'literal': 0.09; 'python': 0.10; 'wed,': 0.15; '"list': 0.16; 'constructor.': 0.16; 'distinction': 0.16; 'handle,': 0.16; 'literal,': 0.16; 'literal.': 0.16; 'received :adsl-dyn.isp.belgacom.be': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sentinel': 0.16; 'unimportant': 0.16; 'wrote:': 0.16; '2015': 0.20; 'constant': 0.22; 'object.': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'chris': 0.26; 'not.': 0.27; 'closer': 0.29; 'received:192.168.1.3': 0.29; 'received:be': 0.30; 'point': 0.33; 'problem': 0.33; 'right?': 0.33; 'open': 0.33; 'file': 0.34; 'except': 0.34; 'fresh': 0.35; 'nov': 0.35; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'expect': 0.37; 'does': 0.39; 'received:192': 0.39; 'rather': 0.39; 'well.': 0.40; 'to:addr:python.org': 0.40; 'still': 0.40; "you'll": 0.61; 'charset:windows-1252': 0.62; 'making': 0.62; 'more': 0.63; 'here': 0.66; 'square': 0.76; 'angelico:': 0.84; 'confusion.': 0.84; 'pardon': 0.84; 'received:195.238': 0.84; 'schreef': 0.84 X-Belgacom-Dynamic: yes X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2CWAQDGclRW/9Xi9VENUYR9wRuGDwKBdRABAQEBAQEBhT4BAQEDAXgGCwsYCRYPCQMCAQIBRRMGAgKIIg2tM4x5hCYBAQgCASCGVIR+hSeEEgEEjR6JMo0xnEs4hDBxAYUqAQEB 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:99340 Op 24-11-15 om 15:00 schreef Chris Angelico: > On Wed, Nov 25, 2015 at 12:43 AM, Antoon Pardon > wrote: >> I think that part of the problem is, that [] is not a constant object. So >> that when you see a line like >> >> ls = [] >> >> It behaves more lke >> >> ls = [].copy() >> >> than what you would expect with the normal python semantics. > > You're still thinking in terms of [] being a literal. It isn't; the > docs describe it as "list display", and it's closer to: > > ls = list() No I am not. The distinction you are making here is unimportant for the point I am making. And that is that although v = () and v = [] look very similar. They behave differently. > except that it doesn't look up the global name. Every time you call > open(), you expect it to open a fresh file handle, right? (Even if you > use the same file name.) And every time you call object(), you get a > new and unique sentinel object. It's the same with list(), and it's > the same with square brackets as well. > > Start thinking of it as a constructor call rather than a literal, and > you'll get past most of the confusion. That doesn't change the fact it does look like a literal and not like a constructor. -- Antoon.