Mutability of function arguments?

Kent Johnson kent at kentsjohnson.com
Thu Dec 8 06:11:36 EST 2005


Mike Meyer wrote:
> "ex_ottoyuhr" <ex_ottoyuhr at hotmail.com> writes:
> 
>>I'm trying to create a function that can take arguments, say, foo and
>>bar, and modify the original copies of foo and bar as well as its local
>>versions -- the equivalent of C++ funct(&foo, &bar).
> 
> 
> C++'s '&' causes an argument to be passed by reference. Python does
> that with all arguments. Any changes you make to the argument in the
> function will be seen in the caller unless you explicitly make a copy
> to pass.

I would say, from the point of view of a C++ programmer, Python passes 
references by value. In other words if you think of variables as 
pointers (references) to values, and function call as passing the 
reference by value, the behaviour of Python makes sense.

Kent



More information about the Python-list mailing list