Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'english.': 0.04; 'argument': 0.05; 'insert': 0.05; 'attribute': 0.07; 'correct.': 0.07; 'expressions': 0.07; 'string': 0.09; '??,': 0.09; 'arguments': 0.09; 'don': 0.09; 'expected.': 0.09; 'false,': 0.09; 'modifies': 0.09; 'used.': 0.09; 'python': 0.11; 'creates': 0.14; 'language.': 0.14; '"a"': 0.16; '"and"': 0.16; '"b"': 0.16; '"or"': 0.16; '[5]': 0.16; 'boolean': 0.16; 'dict': 0.16; 'distinct': 0.16; 'expression.': 0.16; 'integers,': 0.16; 'merely': 0.16; 'mutable': 0.16; 'nick': 0.16; 'object).': 0.16; 'objects.': 0.16; 'operands,': 0.16; 'slice,': 0.16; 'stumbling': 0.16; 'tripped': 0.16; 'tuple': 0.16; 'tuples,': 0.16; 'wrote:': 0.18; 'value.': 0.19; '>>>': 0.22; 'programming': 0.22; 'header :User-Agent:1': 0.23; 'integer': 0.24; 'lets': 0.24; 'specify': 0.24; 'this:': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'tim': 0.29; 'related': 0.29; 'evaluation': 0.30; 'returned': 0.30; 'statement': 0.30; '(which': 0.31; 'container': 0.31; 'context,': 0.31; 'names.': 0.31; 'object.': 0.31; 'probably': 0.32; 'critical': 0.32; 'another': 0.32; 'up.': 0.33; "i'd": 0.34; 'except': 0.35; 'knows': 0.35; 'objects': 0.35; 'but': 0.35; 'there': 0.35; '(we': 0.36; 'object,': 0.36; 'two': 0.37; 'list': 0.37; 'list.': 0.37; 'being': 0.38; 'same.': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'anything': 0.39; 'does': 0.39; 'itself': 0.39; 'to:addr:python.org': 0.39; 'space': 0.40; 'how': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'expression': 0.60; 'new': 0.61; "you're": 0.61; "you'll": 0.62; 'name': 0.63; 'happen': 0.63; 'our': 0.64; 'different': 0.65; 'received:74.208': 0.68; 'containing': 0.69; 'below.': 0.71; 'of*': 0.84; 'received:74.208.4.194': 0.84; 'subject:gets': 0.84 Date: Wed, 19 Jun 2013 01:42:02 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: python-list@python.org Subject: Re: A certainl part of an if() structure never gets executed. References: <51ba6e92$0$29997$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:vhDUT3SU1cQtI5bwkXhLghSaZI+a2qWHja0RH8cg2vw LHFNZCE1v2OXrPq0ny3Pj3vG2nsCBH30fr9hoE0XtLA2pBPv/+ k6tzPdY6w8cVhlKrp+6USm09vj5AT12clH+JbD35e9ucxNjnlU J8szCGn9fOjzXUlsBTfnbhSwRYgYtgKXsiUzi4hqaLppUN/ZTW Btv0/pxRC7GubOgDq3o4lwo/K8CYRKiI3/qlaONuxQqn4/L9wi BFHlVZ2uYn9TBI09n10+I3yz1rw9NXRLZ38zhlSGE4q/fD6KLt Sfj7LfzXAI/ZjrdMVmne6M9YbQu2UF3AvlZIpDg2hYe31Wm6Ti xZTeclpfRLMI3K/pwdSs= 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: 85 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371620544 news.xs4all.nl 15984 [2001:888:2000:d::a6]:60213 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48686 I think this is an excellent description of name binding with mutable objects. I just have one clarification to insert below. On 06/19/2013 01:08 AM, Tim Roberts wrote: > Nick the Gr33k wrote: >> >> On 16/6/2013 4:55 ??, Tim Roberts wrote: >> >>> Nick the Gr33k wrote: >>> Because Python lets you use arbitrary values in a Boolean context, the net >>> result is exactly the same. >> >> What is an arbitrary value? don even knwo what arbitrary means literally >> in English. > > Basically, it means "any". In Python, you can use ANY value where a > Boolean is expected. All types have a Boolean meaning. For integers, 0 is > false, anything else is true. For strings, an empty string "" is false, > anything else is true. For lists, an empty list [] is false, anything else > is true. For tuples, an empty tuple () is false, anything else is true. > For dicts, an empty dict {} is false, anything else is true. > >> The argument being returned in an "and" or "or" expression is the one >> that *determined' the evaluation of the expression. > > That's not exactly how I'd put it, but the statement is correct. The last > thing it had to evaulate is the result of the expression. > >> And actually what's being returned is not the argument itself but the >> argument's value. > > But this is no different than any other programming language. Expressions > always use the value of their operands, and they always return a value. > > The name vs value thing is critical to understanding Python, in my opinion, > and it can be a stumbling block when you're coming from another language. > Here's how I think about it. > > Python had two distinct spaces: there is a space for names, and there is a > space for objects (which are values). Objects live in a nameless, faceless > object cloud. > > A name is always bound to some object (which might be the "None" object). A > name always knows its object, but an object never knows what names it is > bound to. > > The only things that can be used in expressions and function arguments are > objects. Names are merely the way we specify which objects to be used. Names are *one of* the ways we specify which objects are to be used. (We can also specify objects via an container and a subscript or slice, or via an attribute of another object. And probably another way or two.) > > a = [3] > > That creates a nameless list containing a single integer object with the > value 3. It then binds the name "a" to that list. Note that the list has > no clue that it is bound to any names. > > b = a > > That binds "b" to the same list. "b" and "a" are not related in any way, > except that they happen to be bound to the same object. Note that there is > still only one list. > > a.append(4) > > That modifies the list so that it now contains [3,4]. b is bound to the > same list, so if you > print(b) > you'll see [3,4] > > Now, let's say I do this: > > a = [5] > > Here's where people get tripped up. This does not change our original > list. Instead, it creates a new nameless list containing 5, and binds the > name a to that list. a and b are no longer bound to the same object. > -- DaveA