Pass by reference or by value?

James Stroud jstroud at
Fri Jul 13 21:34:47 CEST 2007

Robert Dailey wrote:
> I actually want to know how to "pass by
> reference", in that any changes made to a parameter inside of a
> function also changes the variable passed in.

Pass a mutable type.

py> class C(object):
...   def __repr__(self):
...     return str(self.value)
...   def __init__(self, v):
...     self.value = v
py> c = C(4)
py> c
py> def doit(v):
...   v.value = v.value * 2
py> doit(c)
py> c


James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

More information about the Python-list mailing list