passing by refference

Joshua Marshall joshway_without_spam at myway.com
Thu May 15 16:18:03 EDT 2003


Daniel Fackrell <unlearned at deletethis.learn2think.org> wrote:
...

> Consider:

>>>> def append(l, item):
> ...     l.append(item)
> ...
>>>> l = [1, 2, 3]
>>>> l
> [1, 2, 3]
>>>> append(l, 4)
>>>> l
> [1, 2, 3, 4]

> How can this be explained by call-by-value?

A reference is traversed--the object at the end of it is modified.  A
variable in the caller's scope also refers to this object, and
therefore sees the change at the end of its own reference.

> As pointed out by (I believe) Fredrik Lundh and Tim Peters, the traditional
> uses of the terms call-by-value and call-by-reference both fall short of
> describing Python's passing scheme in important ways.

We disagree, but that's fine.  In fact the original poster has said
he's gotten some valuable information from this discussion, so maybe
we've even done some good.




More information about the Python-list mailing list