anything like C++ references?

Michael Chermside mcherm at
Wed Jul 16 15:26:01 CEST 2003

Stephen Horne writes:
> 'value' is a term which has meaning in mathematics and computer
> science. Values are *always* immutable, whatever language you use.
> In Python, assignment takes a name and binds it to an object (or a
> pointer to that object).
> In C/C++, assignment takes a name and binds it to a symbolic
> representation of a value.
> Objects can be mutable. Representations can be mutable. However, using
> that mutability should respect the idea from mathematics of variables
> binding to values. The fact that the binding is implemented using
> objects or symbolic representations is irrelevant - they are low level
> implementation details. You shouldn't have to worry about them in a
> 'very high level' language.
> Of course if you explicitly ask to deal with the object (rather than
> the value) that is a different thing. But that isn't the case in
> Python. It fails to respect the mathematical concept of variables
> binding to values BY DEFAULT. This regularly causes confusion and
> errors.


AHA! I think I've got it. Your problem is that you are expecting
Python to operate on values -- and it DOESN'T. When I write
    x = 2
in python, it is NOT binding the variable "x" to the value 2. Instead,
it is binding the variable "x" to the OBJECT 2. Of course, since
int objects are immutable, this difference is meaningless pedantry.
But as soon as you write
    x = MyObject()
the difference quickly becomes meaningful.

So there are several ways one could "fix" Python to match your
expectations. One would be to introduce "values"... right now, Python
has only objects at the language level, and the "values" are a
theoretical construct built on top of that. Another would be to
make all objects immutable, then the distinction between objects and
values could become a mere implementation detail, and the language
could be said to contain "values". But as things stand, "values"
(as you define them) do not exist in Python.

I submit that you may find this be a more useful way to view things --
not that Python's implementation of assignment fails to match your
expectation, but that Python provides no true access to "values", only
to the more complex construct "objects" (although a strong equivalence
exists  for immutable types).

Do you find this alternate explanation useful?

-- Michael Chermside

More information about the Python-list mailing list