Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Oscar Benjamin Newsgroups: comp.lang.python Subject: Re: What is a function parameter =[] for? Date: Thu, 19 Nov 2015 18:44:50 +0000 Lines: 41 Message-ID: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de cAtuH1dz1QB0ysLI1GfXTQzAOtoUZm3yWMrlVHVLoxCA== 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; 'pycon': 0.03; 'context': 0.05; 'cpython': 0.05; 'used.': 0.05; 'semantic': 0.07; 'cc:addr :python-list': 0.09; 'incorrect': 0.09; 'pointers': 0.09; 'through,': 0.09; 'python': 0.10; 'talks': 0.11; '(assuming': 0.16; 'above)': 0.16; 'cc:name:python list': 0.16; 'comprehend': 0.16; 'distinct': 0.16; 'distinction': 0.16; 'expressions)': 0.16; 'helps.': 0.16; 'quoted': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'saying.': 0.16; 'wrote:': 0.16; 'looked': 0.16; 'copied': 0.18; 'pointer': 0.18; '>>>': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '(the': 0.22; 'names.': 0.22; 'object.': 0.22; 'bit': 0.23; 'consistent': 0.23; 'previously': 0.24; 'header:In-Reply-To:1': 0.24; 'followed': 0.27; 'message-id:@mail.gmail.com': 0.27; 'implied': 0.29; 'objects': 0.29; 'creating': 0.30; 'operations': 0.31; 'post': 0.31; 'another': 0.32; 'statement': 0.32; 'usually': 0.33; 'right?': 0.33; 'received:google.com': 0.35; 'something': 0.35; "isn't": 0.35; 'but': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'associated': 0.38; 'received:209': 0.38; 'names': 0.38; 'someone': 0.38; 'mean': 0.38; 'some': 0.40; "you'll": 0.61; 'linked': 0.63; 'please,': 0.63; 'different': 0.63; 'necessarily': 0.63; 'between': 0.65; 'talking': 0.67; 'subject': 0.70; 'carefully': 0.72; 'article': 0.77; 'contains.': 0.84; 'distinguish': 0.84; 'implications': 0.84; 'oscar': 0.84; 'remark': 0.84; 'remarks': 0.84; 'adopt': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=krh9FSuVTv5zYzHJErVIO0yFACYvOFbX5KREzLATJNM=; b=fV9IwJOeMhF/ObeovgVLE/+RxALW8T1vw23/k7u5RmK5b05F+nGdaJtT9rO2W7Yk/X ekHTppI07LvKWu26Hc1BtNRBpOJmXXfbVfyvw+AvDnawi1zoK8NVnqUHnd5uUYbDUJOv QSpI5wkOr5CZAVyV76q+E8515jBGebZjaxDouuboEdWTGdcnWXBKCfEYinpFZMvb9XZs uTZ97M9gA5XDyMQ+S6iUr9kSWySGgQfdOvkSWHvA6QmCl8nMlO9BV9YxLb9JtSrXMzV0 BEfVNekX1XchAmtR6b29GKwiotMAjMjXkSG20rk/2gEQo1KNAc3aFmhPHWlQ8qpc4msg /N6g== X-Received: by 10.25.148.202 with SMTP id w193mr4188357lfd.130.1447958710652; Thu, 19 Nov 2015 10:45:10 -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:99083 On 19 November 2015 at 18:19, BartC wrote: >>> >>> if you write A=B then something of B needs to have been copied into >>> A, even if it's just the reference that B contains. Otherwise it would be >>> difficult to get A to refer to the same object as B. >> >> Please, PLEASE, go and read/watch Ned's PyCon talk (the one I linked >> you to earlier). Don't post another word on this subject until you >> comprehend what he is saying. > > I looked through the long article (I don't remember seeing a link to a > video), and followed it up to about 3/4 of the way through, then it got a > bit heavy. > > But what is it about my remarks above that isn't right? It's not necessarily incorrect (just focussing on the remark quoted above) but you'll find it easier to understand the model if you adopt the same terminology that is usually used. When talking of "copying" in a Python context something different is implied than what happens with A=B. The statement A=B (assuming A and B are names and not expressions) simply binds the name A to the same object that the name B is bound to. In the implementation of CPython the names are associated with pointers and the value of the pointer associated with B is copied to the pointer associated with A. Another implementation may not use pointers but there will in some way be a "reference" that is "copied" over if you like to view it that way. However in a Python context when someone talks of "copying" they will mean something different: creating a new object which is distinct from, but has the same value as, some previously existing object. It is important in Python to distinguish between operations that create/mutate objects and operations that rebind names. This distinction has semantic implications that are not hard to understand if you think about them carefully and consistent use of terminology really helps. -- Oscar