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: Wed, 25 Nov 2015 03:38:05 +1100 Lines: 46 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> <56547337.4000709@rece.vub.ac.be> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de 8cpFMFlMvhr4GcmK3UEMiQx48Okc5Jok4OpdwdxRJ3Zw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'constructor': 0.07; 'cc:addr:python-list': 0.09; '[1,': 0.09; 'literal': 0.09; 'python': 0.10; 'assume': 0.11; 'syntax': 0.13; 'wed,': 0.15; 'confusion': 0.16; 'constructor.': 0.16; 'definition.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hides': 0.16; 'literal,': 0.16; 'literal.': 0.16; 'literals': 0.16; 'literals,': 0.16; 'operators.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'token,': 0.16; 'wrote:': 0.16; 'instance,': 0.18; '>>>': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'tuples': 0.22; 'am,': 0.23; 'seems': 0.23; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'chris': 0.26; 'define': 0.27; 'message- id:@mail.gmail.com': 0.27; 'idea': 0.28; 'values': 0.28; 'equally': 0.29; 'certainly': 0.30; 'regardless': 0.31; 'probably': 0.31; 'url:python': 0.33; 'handle': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'ones': 0.35; 'nov': 0.35; "isn't": 0.35; 'but': 0.36; 'should': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; '(and': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'display': 0.37; 'list.': 0.37; 'things': 0.38; 'itself': 0.38; 'received:209': 0.38; 'does': 0.39; 'rather': 0.39; 'where': 0.40; 'still': 0.40; 'url:3': 0.60; "you'll": 0.61; 'is.': 0.63; 'chrisa': 0.84; 'confusion.': 0.84; 'pardon': 0.84; 'to:none': 0.91; 'url:reference': 0.91; 'from.': 0.93 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=6UtnCnBUix6b6BQCfhhfUlVVRIorBlmVsBTrssHvlZ0=; b=0uvezHBS54NHvC2hZcapDRm3H6DR4P6mSsQAwzVclTfEOfJNS0rchnu2CyfSmxT75h zbD+JXKuoaxIAEXFwu8UqmG92/SqLNCaGw8gWT+KzThdoJrt20Wt+0NWOKKyPBoiIA0j Y4DXFltMnX/b3qW/553egR2/sc+U8cGXay/NnzcCjUgjQGr4535UYre7Eakw+jJqPBNr zFpuI4CYO8pkqLnIo1zv7MBYY+vUSVsW8Fxgt0evdGHZbFadnLiZZzhGlfF4pmoQLeqa V7klyJl0Il3e+yFpWp9IgZJ8yy65I8oQJNlHqAbGhF3ym1A79Ha6zbmTOsvgpJXE0pTu EMww== X-Received: by 10.107.3.163 with SMTP id e35mr28537211ioi.157.1448383085736; Tue, 24 Nov 2015 08:38:05 -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:99364 On Wed, Nov 25, 2015 at 3:28 AM, Random832 wrote: > On 2015-11-24, Chris Angelico wrote: >> On Wed, Nov 25, 2015 at 1:24 AM, Antoon Pardon >> wrote: >>>> 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. >> >> Neither of them is a literal, even though one of them isn't even >> constructing a list. Tuples may be constant, but they still don't have >> a literal form. > > How do you define "literal form"? I define it as any syntax that > can participate in ast.literal_eval (And I consider [...] to be a > literal form regardless of whether the ... values are literals or > not). I don't think "Start thinking of it as a constructor call > rather than a literal" is helpful, since it just hides one's > confusion about what a literal is. https://docs.python.org/3/reference/lexical_analysis.html#literals ast.literal_eval can handle a number of things which are not literals, as long as they use nothing but literals combined by a restricted set of operators. For instance, Python has no complex literals, only imaginary ones - but: >>> ast.literal_eval("1+2j") (1+2j) And Python certainly doesn't have "expression literals", yet: >>> ast.literal_eval("[1,1+1,3]") [1, 2, 3] Its support for list display equally doesn't make that into a literal. > The Python documentation itself seems to assume that "literal" > should only be used for things that are a single token, though I > have no idea where this thinking comes from. Probably the grammar. In other words, it's part of the language's very definition. ChrisA