Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.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; 'assign': 0.07; 'element': 0.07; 'subject:Question': 0.07; '"if': 0.09; '22,': 0.09; 'assigning': 0.09; 'caller': 0.09; 'method,': 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; 'changes': 0.15; '"arguments': 0.16; '"create': 0.16; 'function;': 0.16; 'mutable': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:object': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'header:User-Agent:1': 0.23; 'refers': 0.24; 'pass': 0.26; 'gets': 0.27; 'header:X-Complaints- To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; "i'm": 0.30; 'container': 0.31; 'but': 0.35; 'there': 0.35; 'done,': 0.36; 'object,': 0.36; 'method': 0.36; 'thanks': 0.36; 'subject:?': 0.36; 'on-line': 0.38; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'changed': 0.39; 'received:org': 0.40; 'then,': 0.60; "you're": 0.61; "you'll": 0.62; 'name': 0.63; 'july': 0.63; 'refer': 0.63; 'within': 0.65; 'here': 0.66; 'jul': 0.74; 'contents,': 0.84; 'received:pacbell.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: emile Subject: Re: Question about Pass-by-object-reference? Date: Tue, 22 Jul 2014 16:10:42 -0700 References: <986eee35-0327-46e5-bce0-b1ae4572dd8f@googlegroups.com> <8b5a4a1f-656b-4871-91c4-2091209eafe3@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-69-226-129-65.dsl.pltn13.pacbell.net User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: <8b5a4a1f-656b-4871-91c4-2091209eafe3@googlegroups.com> 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1406070670 news.xs4all.nl 2864 [2001:888:2000:d::a6]:52459 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75041 On 07/22/2014 04:00 PM, fl wrote: > On Tuesday, July 22, 2014 4:35:33 PM UTC-4, Peter Pearson wrote: >> On Tue, 22 Jul 2014 12:34:51 -0700 (PDT), fl wrote: >> When you say "def reassign(list)", that means "I'm defining a function >> to which the caller will pass one object, and within this function I'm >> going to refer to that object by the name 'list'." >> >> >> >> Then, when you say "list=[0,1]", that means "Create the object [0,1], > > The above is what rebind? see below I cite. exactly. assigning to a variable within a function makes that variable local to the function; assigning to the contents (as with [:]) changes the contents, but not the container variable, and as the container element was passed in you'll see the changed item outside the function. Emile > >> and assign to it the name 'list'." At this point, there is no longer >> any name that refers to the object that the caller passed. > > Here is I find on-line about "Arguments are passed by assignment." > http://stackoverflow.com/questions/986006/python-how-do-i-pass-a-variable-by-reference > > "If you pass a mutable object into a method, the method gets a reference to that > same object and you can mutate it to your heart's delight, but if you rebind the > reference in the method, the outer scope will know nothing about it, and after > you're done, the outer reference will still point at the original object." > > Thanks >