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:00:28 +1100 Lines: 28 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=UTF-8 X-Trace: news.uni-berlin.de NjuxW9vrsaVPyp7s3r1jGQTmleoQ35OiXZoi+gv4C6rw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '(even': 0.05; 'constructor': 0.07; 'cc:addr:python-list': 0.09; 'brackets': 0.09; 'python': 0.10; 'wed,': 0.15; '"list': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'handle,': 0.16; 'literal,': 0.16; 'literal.': 0.16; 'received:209.85.213.176': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sentinel': 0.16; 'wrote:': 0.16; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'constant': 0.22; 'object.': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'message-id:@mail.gmail.com': 0.27; 'closer': 0.29; 'problem': 0.33; 'right?': 0.33; 'open': 0.33; 'file': 0.34; 'except': 0.34; 'received:google.com': 0.35; 'fresh': 0.35; 'nov': 0.35; 'received:209.85': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'expect': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'rather': 0.39; 'well.': 0.40; 'still': 0.40; "you'll": 0.61; 'more': 0.63; 'square': 0.76; 'chrisa': 0.84; 'confusion.': 0.84; 'pardon': 0.84; '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=yFhhFEijZY/1hwppVhS2AnoyfrYGS3hEWeyQPHnCNv4=; b=gGljBkVy+F5NWrnp+wyUtODHu6/2rzLYsP0Xefilqu3NQF5TkRaZ9k6k8jdXe8zJQn 1IrBCfkjE5j9itvW2+nIgwOChDj1cLg1z/yXvQLsYHLSv6b3fL6Bwf31/Rm9rqZK6lwE nI8jB6j4lGlE+SYsm1V7GWyNc/D4GZlimU3X+Vf02S5AS72y7aGAnPEj8pb/mY7DzYhY cIixzxHzCzffDUGTe48RgaWK8IbF8RgERWVpQJb0EPpHz/7itL6UeM6zTuWdNPff93P2 MtkoA1lmoXL50y+dGfVgR1wGWlD1b2Yo8zZOPfiTFZN170GC8+LaZRgOiPeedFRU3tav 22SQ== X-Received: by 10.50.83.38 with SMTP id n6mr17813534igy.92.1448373629047; Tue, 24 Nov 2015 06:00:29 -0800 (PST) In-Reply-To: <56546985.8060704@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:99333 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() 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. ChrisA