Python Args By Reference

Dan Bishop danb_83 at yahoo.com
Tue May 10 21:04:07 EDT 2005


Joseph Garvin wrote:
> ncf wrote:
>
> >Hello all, I was wondering if there was any way to pass arguments
> >(integer and such) by reference (address of), rather than by value.
> >
> >Many thanks in advance.
> >
>
> All mutable types in python are passed by reference automatically.

More accurately:

(1) All function arguments are passed by value, but
(2) All "values" are pointers.

Statement (2) also explains why

>>> a = [1, 2, 4]
>>> b = a
>>> b[1] = 0
>>> print a
[1, 0, 4]

behaves the way it does.

And there's no difference between mutable and immutable types.  It's
just that with immutable types, it doesn't matter how they're passed.




More information about the Python-list mailing list