Pass by reference or by value?

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Sat Jul 14 00:46:06 EDT 2007


Robert Dailey a écrit :
> On Jul 13, 2:10 pm, Robert Dailey <rcdai... at gmail.com> wrote:
> 
>>Hi,
>>
>>I noticed in Python all function parameters seem to be passed by
>>reference. 
(snip)
> 
> Correction:
> 
> I ran a few more tests and python actually does a pass by value,
(snip)

Still wrong !-)

Python passes references to objects, but the *names* are local. So while 
*mutating* (ie: calling a method that changes the state of) an object in 
a function will impact the object outside the function, *rebinding* a 
name will not impact the name outside the function.

But anyway, as Star mentionned, Ben Finney gave a pretty good (IMHO) 
explanation in the nearby thread named "understanding python functions".



More information about the Python-list mailing list