Finding the instance reference of an object
greg at cosc.canterbury.ac.nz
Fri Oct 31 08:07:16 CET 2008
Joe Strout wrote:
> (Perhaps explaining why there appears to be far more
> confusion about call semantics in the Python community than in the
> community of other languages where the default semantics are exactly
> the same.)
I think part of the problem stems from the fact that the
word "value" is often used rather loosely in relation to
Python, sometimes to mean a reference to an object and
sometimes to the contents of the object itself. So there's
a tendency to avoid using it when trying to speak
precisely. Some even go so far as to declare that there is
no such thing as a "value" in Python.
Then people see the term "call by value", and have a
fit of apoplexy because it has the forbidden word "value"
in it. How can we apply this term, they say, if we can't
decide what a value is?
The way out is to realise that you don't *have* to assign
any meaning to the term "value" in order to apply the
term "call by value".
If you look at the definitions I posted, you'll notice that
I carefully avoided using the terms "value", "reference",
"variable", "address" or any other such controversial words.
I did use the notion of the "result of evaluating an
expression", but only in the context of assigning it to a
name. Nobody seems to have any qualms talking about that in
Python, as far as I know.
So in summary, just treat the terms "call by value" and
"call by reference" as atomic identifiers, defined in terms
of assignment semantics. Don't try to pick them apart and
understand them in terms of "values" and "references".
More information about the Python-list