Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.stack.nl!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.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'python,': 0.02; 'subject:Python': 0.06; 'amtsgericht': 0.07; 'hrb': 0.07; '[1,': 0.09; 'means,': 0.09; 'reference:': 0.09; 'def': 0.12; 'a()': 0.16; 'finney': 0.16; 'foo.': 0.16; 'rainer': 0.16; 'ralf': 0.16; 'value;': 0.16; 'wrote:': 0.18; 'variable': 0.18; '>>>': 0.22; 'gmbh': 0.22; 'otherwise,': 0.22; 'header:User-Agent:1': 0.23; 'germany': 0.24; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'assert': 0.31; 'values.': 0.31; 'writes:': 0.31; 'class': 0.32; 'list': 0.37; 'ben': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'consists': 0.60; 'received:194': 0.64; 'subject:The': 0.64; 'skip:+ 10': 0.65; 'tel.:': 0.65; 'press': 0.70; 'subjectcharset:utf-8': 0.72; 'behavior': 0.77; 'subject:have': 0.80; '"spam"': 0.84; "'foo'": 0.84; '*and*': 0.84; 'received:192.168.57': 0.84; 'hand,': 0.93 Date: Thu, 08 May 2014 09:26:57 +0200 From: Johannes Schneider User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131103 Icedove/17.0.10 MIME-Version: 1.0 To: python-list@python.org Subject: Re: The =?UTF-8?B?4oCcZG9lcyBQeXRob24gaGF2ZSB2YXJpYWJsZXM/4oCdIGQ=?= =?UTF-8?B?ZWJhdGU=?= 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> In-Reply-To: <85eh05cdjx.fsf@benfinney.id.au> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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: 64 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1399536019 news.xs4all.nl 2830 [2001:888:2000:d::a6]:48957 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:71084 On 08.05.2014 02:35, Ben Finney wrote: > Marko Rauhamaa writes: [..] > 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] [..] IMHO this is the behavior of having a variable pointing to it's value; foo to the list and bar to foo. consider the following: >>> def f(l): ... l[1] = 'foo' ... >>> l1 = [1,2,3] >>> f(l1) >>> l1 [1, 'foo', 3] this means, l1 consists of "pointers" to its values. Otherwise, it's not calling by reference, because >>> g(l1) >>> l1 [1, 'foo', 3] does not change l1. Once again, if I pass an object it behaves like calling by reference: >>> class A: ... a = 0 ... >>> a = A() >>> a.a 0 >>> def h(a1): ... a1.a = 1 ... >>> h(a) >>> a.a 1 bg, Johannes -- Johannes Schneider Webentwicklung johannes.schneider@galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn