Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'languages,': 0.04; 'assign': 0.07; 'assignment': 0.07; 'element': 0.07; 'attributes': 0.09; 'raises': 0.09; 'references.': 0.09; 'statements': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'assignment.': 0.16; 'bindings.': 0.16; 'evaluates': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'statements,': 0.16; '(you': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'all,': 0.19; 'trying': 0.19; "python's": 0.19; '(the': 0.22; 'feb': 0.22; '(in': 0.22; 'cc:addr:python.org': 0.22; 'adds': 0.24; "aren't": 0.24; 'instance,': 0.24; 'pointer': 0.24; 'mon,': 0.24; "haven't": 0.24; 'cc:2**0': 0.24; 'references': 0.26; 'pass': 0.26; 'least': 0.26; 'certain': 0.27; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'subject:list': 0.30; 'message- id:@mail.gmail.com': 0.30; 'usually': 0.31; '(unless': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'class': 0.32; 'says': 0.33; "can't": 0.35; 'except': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'c++': 0.36; 'possible': 0.36; 'pm,': 0.38; 'anything': 0.39; 'structure': 0.39; 'read': 0.60; 'expression': 0.60; 'referred': 0.60; 'most': 0.60; 'areas': 0.61; 'simple': 0.61; 'name': 0.63; 'refer': 0.63; 'side': 0.67; 'believe': 0.68; 'statement,': 0.68; 'results': 0.69; 'square': 0.74; '"not': 0.84; 'to:none': 0.92 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=9MPsOmwwpRZN4/Dgc83HE206Zj6AOoC72PKc47biO6s=; b=k9ATnc+IwCr4DxzYiJgeEqIK62NLINbCGmuUn4QWn5GYH6miNmATuZeMZo0j/sJZGE QFxhqYj95aQ80ZXPvUT1gteCT0xAf9MpYGyjXdZ8qhc1LJ34gZNlLR54t8ywT16sr1Ug ixtqMHOICnRkgNlpfEhsORt/wZQDd5UCSqa5thz+EIWEm0OPhNJgfQSh0isSs7N/x+0L UDPqgTDfsCn/hudR1ARjVrlpZMGlsk84am14e6IzN448k77bba/JKsJA8m6KrLf7+CwC /+NXN6NGGROLJN9RC+WTmOMeqU24H1v+fld6pw0ABd3REYa1eXgCVB1R3rA4qZ2tb1/b fZOg== MIME-Version: 1.0 X-Received: by 10.66.25.241 with SMTP id f17mr24649714pag.127.1392621088236; Sun, 16 Feb 2014 23:11:28 -0800 (PST) In-Reply-To: <5301aa63$0$29985$c3e8da3$5496439d@news.astraweb.com> References: <13208de8-0f85-4e60-b059-dc087c8fda41@googlegroups.com> <52fefccc$0$29973$c3e8da3$5496439d@news.astraweb.com> <52ff0dc5$0$29973$c3e8da3$5496439d@news.astraweb.com> <5301aa63$0$29985$c3e8da3$5496439d@news.astraweb.com> Date: Mon, 17 Feb 2014 18:11:27 +1100 Subject: Re: Explanation of list reference From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392621097 news.xs4all.nl 2871 [2001:888:2000:d::a6]:55380 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66590 On Mon, Feb 17, 2014 at 5:21 PM, Steven D'Aprano wrote: > So before you ask: for-loops aren't things (values). Neither are while- > loops, try...except blocks, pass statements, del statements, etc. Nor are > names and other references -- I believe that there is a practice in > certain areas of computer science to call them "l-values", which despite > the name are not values at all -- at least not in Python. Usually an l-value is something that can go on the left side of assignment, and an r-value is something that can go on the right side of assignment. (In most languages, every l-value is also an r-value, by definition.) In C, for instance, any simple variable is an l-value, except for those that are constants (you can't assign to an array). A dereferenced pointer is also an l-value, as is a structure element reference. An expression usually isn't (unless it results in a dereferenced pointer). C++ adds references. You can always assign to those (the assignment "happens" to the referred-to "thing"). Python says that these things can be assigned to: names, attributes (with dot), and items (with square brackets); I think that's it. Those are Python's l-values. Anything that evaluates to an object reference is an r-value, with the possible exception of function-local names that haven't been assigned to (does it count as "not an r-value" if trying to read it raises an exception?). Python's statements aren't values at all, and can't be referred to. (Though some of them, like class and def, do result in values or name bindings. But you can't refer to the def statement, only to the function object that it creates.) ChrisA