Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3a.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; 'python,': 0.02; 'languages.': 0.04; 'subject:Python': 0.06; 'assignment': 0.07; 'puts': 0.07; 'variables': 0.07; '[1,': 0.09; 'creator': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'variable,': 0.09; 'python': 0.11; 'changes': 0.15; 'container,': 0.16; 'distinct': 0.16; 'finney': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'variable': 0.18; 'value.': 0.19; 'programming': 0.22; '(in': 0.22; 'header:User-Agent:1': 0.23; 'references': 0.26; 'values': 0.27; 'gets': 0.27; 'header:X -Complaints-To:1': 0.27; "doesn't": 0.30; 'statement': 0.30; 'assert': 0.31; 'values.': 0.31; 'writes:': 0.31; 'know.': 0.32; 'languages': 0.32; 'another': 0.32; 'programmers': 0.33; 'c++': 0.36; 'two': 0.37; 'ben': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'tell': 0.60; 'affect': 0.61; 'term': 0.63; 'such': 0.63; 'subject:The': 0.64; 'skip:\xe2 10': 0.65; 'subjectcharset:utf-8': 0.72; '8bit%:27': 0.74; 'other.': 0.75; 'subject:have': 0.80; '"spam"': 0.84; '*and*': 0.84; '1997': 0.84; 'fails,': 0.84; 'received:125': 0.84; 'hand,': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: The =?utf-8?Q?=E2=80=9Cdoes?= Python have =?utf-8?Q?variables?= =?utf-8?Q?=3F=E2=80=9D?= debate Date: Thu, 08 May 2014 10:35:46 +1000 References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <85zjiuea37.fsf_-_@benfinney.id.au> <8738gmxgay.fsf@elektro.pacujo.net> <87tx91warf.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:JeVqDFyfW2pbJTgCwO+l7wsfshI= 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: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1399509361 news.xs4all.nl 2832 [2001:888:2000:d::a6]:35930 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:71062 Marko Rauhamaa writes: > Ben Finney : > > > That's why I always try to say “Python doesn't have variables the way > > you might know from many other languages”, > > Please elaborate. To me, Python variables are like variables in all > programming languages I know. Many established and still-popular languages have the following behaviour:: # pseudocode foo = [1, 2, 3] bar = foo # bar gets the value [1, 2, 3] assert foo == bar # succeeds foo[1] = "spam" # foo is now == [1, "spam", 3] assert foo == bar # FAILS, ‘bar’ == [1, 2, 3] This is because such languages treat each variable as “containing” a value. Assignment puts another copy of the value in the variable, after which those two values have a distinct history. What happens to one value does not affect the other. Python, on the other hand, has this behaviour:: foo = [1, 2, 3] bar = foo # ‘bar’ binds to the value ‘[1, 2, 3]’ assert foo == bar # succeeds foo[1] = "spam" # ‘foo’ *and* ‘bar’ now == [1, "spam", 3] assert foo == bar # succeeds, ‘bar’ is bound to ‘[1, "spam", 3]’ The assignment statement in Python does not put a value in a container, the way it does for variables in many popular languages. Instead, assignment binds the left-hand-side reference (in these examples, names) to the right-hand-side value. Both remain references to the same value until the binding changes to some other value. So Python doesn't have variables in the way programmers coming from many other languages expect. Instead, it has references bound to values. -- \ “Actually I made up the term “object-oriented”, and I can tell | `\ you I did not have C++ in mind.” —Alan Kay, creator of | _o__) Smalltalk, at OOPSLA 1997 | Ben Finney