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 01:34:03 +1100 Lines: 29 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 yLc/2i2KxZ7/+f372deqigci5+tDfVjeOz/i3hax8jkw== 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; 'cpython': 0.05; 'constructor': 0.07; 'expressions': 0.07; 'squares': 0.07; 'cc:addr:python-list': 0.09; 'immutable': 0.09; 'literal': 0.09; 'tuple': 0.09; 'question.': 0.13; 'do,': 0.15; 'wed,': 0.15; 'constants': 0.16; 'constructor.': 0.16; 'folding': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'literal,': 0.16; 'literals': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; '(in': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'constant': 0.22; 'tuples': 0.22; 'am,': 0.23; 'this:': 0.23; 'header:In- Reply-To:1': 0.24; "doesn't": 0.26; 'example': 0.26; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; 'looks': 0.29; 'generally': 0.32; 'though.': 0.33; 'that,': 0.34; 'received:google.com': 0.35; 'involving': 0.35; 'nov': 0.35; "isn't": 0.35; 'but': 0.36; 'received:209.85': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'one,': 0.37; 'received:209.85.213': 0.37; 'list.': 0.37; 'received:209': 0.38; 'does': 0.39; 'rather': 0.39; 'still': 0.40; 'your': 0.60; "you'll": 0.61; 'chrisa': 0.84; 'confusion.': 0.84; 'pardon': 0.84; 'yours': 0.89; 'to:none': 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=pz43qoMFaJRJ0XXV6dTkRKhvDtZrrWSGptd+T2/Bc70=; b=Bs8Mo65BHSMXPDdG0CjE8MjEDakTJ1k+xAFbbMBsLJ8k5QMmVFjgkiyfRaU2FZDLdD OFf8CZn+7rvyhkftr4nJHxUYT2O7GDcI27xRaoykolng5S/5XoUDfHSbg41nUJiZhaI7 PfuSWTTQEP8eOKv/4vGRST9thPEHr/pKISLsePtHjoqRXE4lNNygb0GLvKK1NtUdnhYM 3zL74KH/DcEnJOt4af1OVrN0KPL4rW8dryLcSlsIUlrmGM45IQMuWFnwLNlKt07F73iC nQcVhy0Gf021FwXyz+PJnSkV1qdzW/E4D7CJbzp2UqAyB+hNC6mB3ue35l/pqnl+mVTO PKvA== X-Received: by 10.50.225.38 with SMTP id rh6mr17518472igc.13.1448375643427; Tue, 24 Nov 2015 06:34:03 -0800 (PST) In-Reply-To: <56547337.4000709@rece.vub.ac.be> 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:99342 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. Then explain how this is a literal: squares = [x*x for x in range(int(input("How far? ")))] Or even a simple example like this: coords = (randrange(10), randrange(10)) 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. (Constant folding can make them function the same way literals do, though. If a tuple is constructed of nothing but immutable constants - including an empty tuple - then CPython will generally create a constant for the whole tuple and use that, rather than manually constructing one every time. But the same is true of other expressions involving nothing but constants.) So if it (in your opinion) looks like a literal but isn't one, whose fault is it? Yours or the language's? Not a rhetorical question. ChrisA