passing by refference

Joshua Marshall joshway_without_spam at myway.com
Thu May 15 16:10:22 EDT 2003


Tim Peters <tim.one at comcast.net> wrote:
...

>>>> def f(x):
> ...     x[:] = [-1] * 3
>>>> y = [1, 2, 3]
>>>> f(y)
>>>> y
> [-1, -1, -1]
>>>>

> There's no rational sense in which that can be called call-by-value.

I just noticed something.  From

  http://python.org/doc/current/tut/node6.html

In section 4.6:

  The actual parameters (arguments) to a function call are introduced in
  the local symbol table of the called function when it is called; thus,
  arguments are passed using call by value (where the value is always an
  object reference, not the value of the object). 4.1 When a function
  calls another function, a new local symbol table is created for that
  call.

And a footnote:

  4.1 Actually, call by object reference would be a better
  description, since if a mutable object is passed, the caller will
  see any changes the callee makes to it (items inserted into a list).

I personally still think using "call by object reference" can be
misleading, but the tutorial does say Python uses call-by-value.
If Guido agrees with you, maybe this should be changed.




More information about the Python-list mailing list