passing by refference

Terry Reedy tjreedy at udel.edu
Tue May 13 14:57:46 EDT 2003


"Joshua Marshall" <joshway_without_spam at myway.com> wrote in message
news:b9r933$8q0$1 at ginger.mathworks.com...
> Mel Wilson <mwilson at the-wire.com> wrote:
> > In article <mailman.1052835140.9801.python-list at python.org>,
> > Daan Hoogland <hoogland at astron.nl> wrote:
> >>is passing by reffence possible in python?
>
> >    Everything in Python is passed by reference.
> ...
>
> This is incorrect terminology.  Python has call-by-value semantics,
> not call-by-reference (it is not possible to pass a reference to a
> variable into a function).

To me, call-by-value implies a copy operation, which Python does not
do.  I think call-by-assignment or call-by-name-binding is more
accurate.  Given a definition "def f(parname1, parname2): <body>" and
a call "f(exp1, exp2)" the interpreter evaluates expressions exp1 and
exp2 as usual and then binds parname1 and parname2 to the resulting
objects, but in the local namespace of f instead of in the namespace
where the expressions were evaluated.  A function call is like a
series of cross-namespace assignment statements.  Once this is
understood, the effect of modifying mutable arguments is
understandable.

Terry J. Reedy

...






More information about the Python-list mailing list