Question about Pass-by-object-reference?

emile emile at
Wed Jul 23 01:10:42 CEST 2014

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 <r at> 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.


>> 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."
> "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

More information about the Python-list mailing list