By value or by reference?

Jonathan Ellis jbellis at gmail.com
Mon Oct 18 11:55:29 EDT 2004


Roger Irwin wrote:
> Riccardo Rossi wrote:
>
> > Hi all!
> >
> > How does Python pass arguments to a function? By value or by
reference?
> >
> > Thanks,
> > Riccardo Rossi.
> >
> >
> By reference to an object....See the python tutorial.

Wrong.  Here is the difference between pass by reference and pass by
value to CS types:

>>> def foo(a): a = 1
...
>>> i = 10
>>> foo(i)
>>> print i

With pass-by-reference, i would now be 1.  However, since python is
pass-by-value, it remains 10.

-Jonathan




More information about the Python-list mailing list