Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'resulting': 0.04; 'assignment': 0.07; 'element': 0.07; '[0,': 0.09; 'item.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'statements': 0.09; 'used.': 0.09; 'python': 0.11; 'assignments': 0.16; 'finney': 0.16; 'helps.': 0.16; 'item)': 0.16; 'merely': 0.16; 'object)': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'variables,': 0.16; 'all.': 0.16; 'variable': 0.18; 'trying': 0.19; '(the': 0.22; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'refers': 0.24; 'references': 0.26; 'right.': 0.26; '(for': 0.26; 'header:X-Complaints-To:1': 0.27; 'point': 0.28; "doesn't": 0.30; 'statement': 0.30; 'subject:list': 0.30; 'code': 0.31; 'object.': 0.31; 'spam,': 0.31; 'stands': 0.31; 'writes:': 0.31; 'yourself.': 0.31; 'not.': 0.33; 'third': 0.33; 'could': 0.34; 'case,': 0.35; 'but': 0.35; 'object,': 0.36; 'received:com.au': 0.36; 'example,': 0.37; 'wrong': 0.37; 'two': 0.37; 'list': 0.37; 'ben': 0.38; 'easiest': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'expression': 0.60; 'first': 0.61; 'name': 0.63; 'kind': 0.63; 'different': 0.65; 'skip:\xe2 10': 0.65; 'talking': 0.65; 'between': 0.67; '8bit%:43': 0.74; 'acts': 0.74; 'abandon': 0.84; 'received:125': 0.84; 'yourself,': 0.95 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: Explanation of list reference Date: Sat, 15 Feb 2014 23:21:13 +1100 References: <13208de8-0f85-4e60-b059-dc087c8fda41@googlegroups.com> <917ede6d-db7c-4a8c-8203-27677283776b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: vmx15867.hosting24.com.au X-Public-Key-ID: 0xBD41714B X-Public-Key-Fingerprint: 9CFE 12B0 791A 4267 887F 520C B7AC 2E51 BD41 714B X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-gpg.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:ao31Pnv5eiYEQWPPBE6vqAm4OAs= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 60 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392466895 news.xs4all.nl 2973 [2001:888:2000:d::a6]:56896 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66425 Jussi Piitulainen writes: > In cheese = spam, cheese is the variable while spam is a variable > reference and stands for 42. Oof. This distinction between “variable” and “variable reference” is bogus and unnecessary, and highlights what is wrong with talking about “variable” at all. In the Python code ‘cheese = spam’, “cheese” is a name, and “spam” is a name. Both of them are references (because all names are references). The assignment binds the name “cheese” to whatever object the name “spam” was bound to at that point in time. In either case, a different kind of reference (for example, a list item) could have been used. Names are merely one kind of reference. > > >>> spam = [0, 1, 2, 3, 4, 5] > > >>> cheese = spam > > >>> cheese[1] = 'Hello!' > > >>> spam > > [0, 'Hello!', 2, 3, 4, 5] > > >>> cheese > > [0, 'Hello!', 2, 3, 4, 5] > > The first two statements in case 2 are assignments to variables, just > like in case 1, but the third statement is different: it doesn't > change the value of the variable (the value is still the same object) > but it does change the value (replaces one element of the list with > another). Again, this distinction is nonsense and confusing. What is happening in all those assignments is: A reference (the expression on the left-hand-side of the ‘=’ symbol) is bound to an object (the value resulting from the expression on the right-hand-side of the ‘=’ symbol). In the first two cases, the reference happens to be a name. In the third case, the reference happens to be a list item. > Would it help to say that in case 1 the relevant statement acts on the > variable while in case 2 it acts on the value of the variable? This is > accurate, I just don't know if it happens to be the thing that helps. I think not. What would help is to abandon the “variable” baggage, and focus on what assignment actually does: binds a reference to an object. > One last thing: a variable is not an object. Right. Also: a reference is not an object, but a reference always refers to exactly one object. -- \ “Science is a way of trying not to fool yourself. The first | `\ principle is that you must not fool yourself, and you are the | _o__) easiest person to fool.” —Richard P. Feynman, 1964 | Ben Finney