Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'represents': 0.05; 'level,': 0.07; 'defines': 0.09; 'pointers': 0.09; 'python:': 0.09; 'throws': 0.09; 'variables.': 0.09; 'python': 0.11; 'creates': 0.14; "wouldn't": 0.14; '"a"': 0.16; 'chunks': 0.16; 'different?': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'mutable': 0.16; 'nick': 0.16; 'referencing': 0.16; 'ways:': 0.16; 'language': 0.16; 'wrote:': 0.18; 'variable': 0.18; '>>>': 0.22; 'memory': 0.22; 'header:User-Agent:1': 0.23; '(a)': 0.24; 'integer': 0.24; 'pointer': 0.24; 'references': 0.26; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'am,': 0.29; 'thus': 0.29; 'away.': 0.31; 'changed.': 0.31; 'intellectual': 0.31; 'cases': 0.33; 'sense': 0.34; 'could': 0.34; 'objects': 0.35; 'but': 0.35; 'there': 0.35; 'c++': 0.36; 'url:org': 0.36; 'example,': 0.37; 'list': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'units': 0.60; 'new': 0.61; 'matter': 0.61; 'name': 0.63; 'more': 0.64; 'holding': 0.65; 'between': 0.67; 'yes': 0.68; 'url:htm': 0.73; 'acts': 0.74; 'bite': 0.84; 'subject:gets': 0.84; 'differences': 0.93 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Sat, 15 Jun 2013 11:45:08 -0600 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.12) Gecko/20130105 Thunderbird/10.0.12 MIME-Version: 1.0 To: python-list@python.org Subject: Re: A certainl part of an if() structure never gets executed. References: <2bc90d3b-09c2-4315-9357-ff7f039465e0@googlegroups.com> <51b926a3$0$29997$c3e8da3$5496439d@news.astraweb.com> <51ba6e92$0$29997$c3e8da3$5496439d@news.astraweb.com> <51bb454c$0$29997$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371318322 news.xs4all.nl 15972 [2001:888:2000:d::a6]:41930 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!news.stben.net!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!usenetcore.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:48334 On 06/15/2013 10:18 AM, Nick the Gr33k wrote: > a and b you say are names, which still are memory chunks Yes no matter how you look at it, a dictionary of names and objects is memory and "variables" in that sense. But at a higher level, we can consider the differences with how a language like C defines variables. > In both situations we still have 2 memory units holding values, so hows > that different? Perhaps one could think of python names as more like pointers or references in C. But python references are counted and garbage-collected (more like a C++ reference-counting pointer type). For example, a = 4 makes the name "a" be a reference to the object int(4), which will never ever change in its lifetime (indeed it wouldn't make sense for the integer 4 to change otherwise it wouldn't be a 4). Thus a = a + 1 creates a new object that represents the integer value of 4 + 1, and throws the old object away. >>> a = 5 >>> id(a) 2857664 >>> a = a + 1 >>> id (a) 2857680 >>> Note that the identity (object) of a has changed. If a were a variable in the same sense as C, the identity of a would not change. A mutable object like a list acts more like a variable in some ways: >>> b = [] >>> id(b) 3076765292 >>> b.append(3) >>> id(b) 3076765292 In many cases the distinction is little more than intellectual for all intents and purposes, though it some cases the idea is very powerful. But there a couple of cases where the difference between a variable and a name referencing an object does bite people in Python: http://effbot.org/zone/default-values.htm http://stackoverflow.com/questions/986006/python-how-do-i-pass-a-variable-by-reference