Finding the instance reference of an object

Steven D'Aprano steve at
Fri Oct 31 09:11:45 CET 2008

On Fri, 31 Oct 2008 20:07:16 +1300, greg wrote:

> 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.

I think you're imagining that.

Perhaps you are confused by the fact that there are people (including 
myself) who try to avoid using the term "assign to a variable" and prefer 
to use "bind to a name" instead. But value? Given x=1, what else could 
the value of x be other than the object 1?

> 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?

We know what a value is. A value is the thing denoted by a symbol. In the 
context of Python, the value of the name x is the object bound to that 

> 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".

Call by value already has at least one well-established meaning. It's a 
meaning that isn't compatible with what Python does.

In such languages as Pascal and C, a variable such as x refers to a fixed 
memory location of a known size. The assignment x = 1 sets the bytes at 
that location to the value 1. When you call func(x) the value of x (the 
value 1) is copied to another memory location which is local to the 

The same holds when x is an array. If x is an array of 1MB, then func(x) 
will copy 1MB of bytes into a local variable of func.

> 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".

In other words, in order for "call by value" to have any meaning in 
Python, we have to forget all about the ordinary meaning of the words 
"value" and "references" and just treat them as magic words unrelated to 
"call by value" in any other language.

Might as well call it "call by milk" or "call by fjH?agx" instead.


More information about the Python-list mailing list