Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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; 'subject:Python': 0.06; 'assignment': 0.07; 'memory.': 0.07; 'puts': 0.07; 'variables': 0.07; '[1,': 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; 'logiciel': 0.16; 'programmers.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'underlying': 0.16; 'variable': 0.18; 'value.': 0.19; '>>>': 0.22; 'programming': 0.22; '(in': 0.22; 'header:User-Agent:1': 0.23; 'pointer': 0.24; '---': 0.24; 'references': 0.26; 'values': 0.27; 'gets': 0.27; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'est': 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; '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; 'affect': 0.61; 'protection': 0.63; 'such': 0.63; 'subject:The': 0.64; 'skip:\xe2 10': 0.65; 'virus': 0.65; 'antivirus': 0.68; 'subjectcharset:utf-8': 0.72; 'foreign': 0.74; 'other.': 0.75; 'subject:have': 0.80; '"spam"': 0.84; '*and*': 0.84; 'courrier': 0.84; 'fails,': 0.84; 'skip:\xc3 10': 0.91; 'hand,': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Joseph Martinot-Lagarde Subject: Re: The =?UTF-8?B?4oCcZG9lcyBQeXRob24gaGF2ZSB2YXJpYWJsZXM/4oCdIGQ=?= =?UTF-8?B?ZWJhdGU=?= Date: Thu, 08 May 2014 10:07:11 +0200 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> <85eh05cdjx.fsf@benfinney.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: gns13-1-88-122-220-146.fbx.proxad.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 In-Reply-To: <85eh05cdjx.fsf@benfinney.id.au> X-Antivirus: avast! (VPS 140507-1, 07/05/2014), Outbound message X-Antivirus-Status: Clean 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: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1399536610 news.xs4all.nl 2949 [2001:888:2000:d::a6]:51884 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:71085 Le 08/05/2014 02:35, Ben Finney a écrit : > 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. > For me, names bound to values is the same concept as pointer pointing to memory. bar = foo copies the pointer and not the underlying memory. This is not a foreign concept to C programmers. --- Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com