Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: A name refers to an object, an object has a value, equality compares values Date: Wed, 25 Nov 2015 19:27:47 +1100 Lines: 152 Message-ID: References: <56544BAB.9020709@rece.vub.ac.be> <874mgbpnb5.fsf@elektro.pacujo.net> <486929d1-4caa-403c-89e6-c45d7b447f98@googlegroups.com> <5655035c$0$1609$c3e8da3$5496439d@news.astraweb.com> <201511250055.tAP0tpfO005889@fido.openend.se> <87egfe7f3m.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de eHaUlvaVZiHVdu59OrghxQPHHitVkLgo+Fk7KKC+Agxg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'received:209.85.223': 0.03; 'value,': 0.03; 'resulting': 0.04; 'true,': 0.04; 'binary': 0.05; 'cpython': 0.05; 'python3': 0.05; 'caller': 0.07; 'correct.': 0.07; 'defines': 0.07; 'expressions': 0.07; 'variable,': 0.07; 'cc:addr:python-list': 0.09; '*value*': 0.09; 'braces': 0.09; 'dict': 0.09; 'mutable': 0.09; "object's": 0.09; 'objects.': 0.09; '\xe2\x80\x94': 0.09; 'python': 0.10; 'wed,': 0.15; 'argument': 0.15; 'subject: \n ': 0.15; 'value.': 0.15; '"get': 0.16; '"hello': 0.16; '"to': 0.16; '"use': 0.16; '"value"': 0.16; 'cares': 0.16; 'cause.': 0.16; 'd[key]': 0.16; 'dictionaries': 0.16; 'dictionary,': 0.16; 'dictionary.': 0.16; 'expression.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'function"': 0.16; 'hashable': 0.16; 'hashable,': 0.16; 'key:': 0.16; 'keys.': 0.16; 'keyword,': 0.16; 'left,': 0.16; 'objects;': 0.16; 'pairs': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:object': 0.16; 'subject:values': 0.16; 'tried:': 0.16; 'wrote:': 0.16; 'string': 0.17; 'instance,': 0.18; 'integer': 0.18; 'result,': 0.18; 'tree': 0.18; 'variable': 0.18; '>>>': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'saying': 0.22; 'keys': 0.22; 'object.': 0.22; 'occurs': 0.22; 'suppose': 0.22; 'pass': 0.22; 'defined': 0.23; 'references': 0.23; 'slightly': 0.23; 'specified': 0.23; 'second': 0.24; 'examples': 0.24; 'header:In- Reply-To:1': 0.24; 'all.': 0.24; "doesn't": 0.26; 'linux': 0.26; 'sense': 0.26; 'used,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'yield': 0.27; 'function': 0.28; 'values': 0.28; 'dictionary': 0.29; 'once,': 0.29; 'referenced': 0.29; 'objects': 0.29; "i'm": 0.30; 'print': 0.30; 'becomes': 0.30; 'checks': 0.30; 'compared': 0.30; 'operations': 0.31; 'probably': 0.31; 'another': 0.32; '"the': 0.32; 'statement': 0.32; 'though,': 0.32; 'class': 0.33; 'problem': 0.33; 'url:python': 0.33; 'retain': 0.33; 'rule': 0.33; 'values.': 0.33; 'similar': 0.33; 'case,': 0.34; 'definition': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'execution': 0.35; 'false': 0.35; 'i.e.': 0.35; 'identity': 0.35; 'mapping': 0.35; 'maps': 0.35; 'nov': 0.35; "isn't": 0.35; 'item': 0.35; 'sometimes': 0.35; 'but': 0.36; 'url:org': 0.36; 'created': 0.36; 'received:209.85': 0.36; 'evaluation': 0.36; 'url:library': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'strictly': 0.64; 'within': 0.64; 'compliant': 0.66; "they're": 0.66; 'results': 0.66; 'talking': 0.67; 'worth': 0.67; '8bit%:21': 0.70; 'as:': 0.79; 'about,': 0.84; 'chrisa': 0.84; 'object:': 0.84; 'subject:value': 0.84; 'tree,': 0.84; 'to:none': 0.91; '"how': 0.91; '2014,': 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:content-transfer-encoding; bh=XdPDDKWhpv/csBF1iQpbbfjEVsM1fpZgX8LTzuRGyT8=; b=09z4AZAmMSmL61FJkSFbHB0BfmWMsIltFLTLMzEz4cg0IYgLop1bdWpDoSbY+tU9xp ryo1Ar8/wlfGBIqIk6WuV5A4pAo3HKPk2FyQQwxG0hXau6LxmpbGJqkeCEcaUNSFLicH jqw1xVQWLIlZqNuZ9OyTQ4NMuImP/GCkUBdGpaFm//O6jkqoim7QVS91rJmWx/z2oDC8 bXhGJLBT47NoKPCWwPBq2wvnpz87W4R/Z9Pc4NKZrP6u82ZLZBUw9LI6YZIt/NqLgdnS mAve41wgEDNLgQrPfA2s2ix7MdhSUUhbCQ4Xcr/KLa9VujOuN2qACNIxyk082VBChgeC Y4MQ== X-Received: by 10.107.3.163 with SMTP id e35mr31660287ioi.157.1448440067931; Wed, 25 Nov 2015 00:27:47 -0800 (PST) In-Reply-To: <87egfe7f3m.fsf@elektro.pacujo.net> 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:99420 On Wed, Nov 25, 2015 at 5:44 PM, Marko Rauhamaa wrote: > I don't think the meaning of the word "value" can be restricted in that > way. Let's try to "refactor" the examples I had found in the wild: > > "How to get the value of a variable given its name in a string" > =3D> How to get the object a variable is bound to given the name of the > variable in a string > > "The value of some objects can change. Objects whose value can change > are said to be mutable" > [no change] Agree with these. > "I'm taking the return value of one function and using it as the > argument of another function" > =3D> I'm taking the return object of one function and using it as the > argument of another function > > "Don't get confused =E2=80=94 name on the left, value on the right" > =3D> Don't get confused =E2=80=94 name on the left, object on the right > > "A return statement ends the execution of the function call and > "returns" the result, i.e. the value of the expression following the > return keyword, to the caller" > =3D> A return statement ends the execution of the function call and > "returns" the result, i.e. the resulting object of the expression > following the return keyword, to the caller > > "When we ask python what the value of x > 5 is, we get False" > =3D> When we ask python what the resulting object of x > 5 is, we get > False These are all talking about the value of an expression. Expressions have values, just as objects do; in Python, evaluation of an expression results in some object whose value is the value of the expression. In many cases, the definition of an expression's value has nothing to do with object identity, only value - for instance, when you call methods on strings such as lower(), center(), or format(), they're required to return a string object with a particular value, but there's no rule about that object's identity. On the CPython that I tried: $ python3 Python 3.4.2 (default, Oct 8 2014, 10:45:20) [GCC 4.9.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> s =3D "hello world" >>> s.lower() is s False >>> s.center(len(s)) is s True >>> s.format() is s True A compliant Python would be allowed to return either True or False for each of these; but if you change the 'is' checks to '=3D=3D', they have to all be True, because the given operations don't change the string's *value* at all. Same with integer arithmetic, string concatenation, and so on. > "To display the value of a variable, you can use a print statement" > =3D> To display the value of the object a variable is bound to, you can > use a print statement This one was probably talking to a new programmer. It's often not worth going into extreme detail early on; being slightly sloppy with terminology isn't a problem when what you're really saying is just "use print to find out what your program is doing". > "Get a value of a specified key" > =3D> Get an image object of a specified key Another one that's looking at the value of an expression. In this case, though, the value is defined based on object identity as well as value, so I suppose you could word this as: "Get the object referenced by a specified key" if you wanted to be pedantic. But dictionaries are defined as mapping keys to values, and the value associated with a key happens to be represented by some object. > In a word, it's a lost cause. Doesn't need to be. > It is actually somewhat comical how Python documentation tries, but > fails, to maintain terminological orthodoxy: > > A mapping object maps hashable values to arbitrary objects. [...] > > A dictionary=E2=80=99s keys are almost arbitrary values. Values that ar= e not > hashable, that is, values containing lists, dictionaries or other > mutable types (that are compared by value rather than by object > identity) may not be used as keys. No, this is strictly correct. A dictionary's keys are defined by values, not objects. The dict retains references to the objects used, but it's equality, not identity, that defines the match. >>> class S(str): pass ... >>> k1 =3D S("hello") >>> k2 =3D S("hello") >>> k1 is k2 False >>> k1 =3D=3D k2 True >>> d =3D {k1: 42} >>> d[k2] 42 The *value* of the setter key is what the dictionary cares about, although it does retain the identity of the object: >>> next(iter(d)) is k1 True > Dictionaries can be created by placing a comma-separated list of > key: value pairs within braces > > [...] > > The first object of each item becomes a key in the new dictionary, and > the second object the corresponding value. If a key occurs more than > once, the last value for that key becomes the corresponding value in > the new dictionary. > > [...] > > d[key] =3D value > Set d[key] to value. > > [...] > > values() > Return a new view of the dictionary=E2=80=99s values. > > ht=3Dvalue#mapping-types-dict> These are all talking about the other sense of "value" - the way expressions yield values. If you were to build a binary tree in Python, you'd have a similar concept of the nodes' "values", which would again be represented by Python objects; but to the tree, they're values. It's equivocation on the word "value", but I don't know of a better word for it (I've sometimes used "payload", but that has its own issues). ChrisA