Question about Pass-by-object-reference?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Tue Jul 22 21:56:48 EDT 2014
On Tue, 22 Jul 2014 12:04:09 -0700, fl wrote:
> Hi,
> I learn Python function call on tutorial. There is a link on this
> subject.
> http://robertheaton.com/2014/02/09/pythons-pass-by-object-reference-as-
explained-by-philip-k-dick/
>
> Although it explains clearly, the figure makes me puzzled.
Here is my take on the same question:
http://import-that.dreamwidth.org/1130.html
Feedback is welcome.
> ""Python is different. As we know, in Python, "Object references are
> passed by value".
I'm not sure who said that, but they weren't really being clear. The
mention of "passed by value" is pointless, since it refers only to the
implementation inside the interpreter, and not anything you can see using
Python code. What it means is that under the hood, you have a mysterious
thing called an "object reference". That's just another way of saying
"reference to an object", which is usually implemented as a pointer. When
the interpreter passes an argument to a function, it does so by making a
copy of that pointer (hence "passed by value"). The copy still points to
the same object.
I believe that for people thinking at the level of *Python code*, such
descriptions aimed at the level of the underlying C code inside the
interpreter add heat but no light. They simply cause more confusion than
clarity.
--
Steven D'Aprano
http://import-that.dreamwidth.org/
More information about the Python-list
mailing list