object types, mutable or not?

Ben Finney ben+python at benfinney.id.au
Tue May 15 21:30:26 EDT 2018


Steven D'Aprano <steve+comp.lang.python at pearwood.info> writes:

> On Tue, 15 May 2018 07:29:39 -0700, Mike McClain wrote:
>
> > I had gotten the impression that everything in OOP is an object but
> > you're all saying that variables are not objects.
>
> Perhaps it is better to say every VALUE in Python is an object.

IMO that is better than using the term “variable”, which carries baggage
from other languages when people try learning Python.

But not good enough. It was you, Steven (I think?) who taught me that
using the term “value” interchangeably with “object” is problematic.

That's because, in Python an object can remain the same object, while
its value changes.

    >>> foo = [1, 2, 3]    # A new list now exists.
    >>> foo.append(4)      # It's the same object, but now its value is different.

Therefore, an object is not its value (otherwise, when the value
changes, we necessarily have a different object. That's false, and so
the equivalence is also false.)

An object is not a value; an object *has* a value. The object retains
its identity even when its value changes.

> Variables *hold* values, or if you prefer, names refer to values. But
> since they aren't themselves values, names/variables aren't objects.

I really want that sentence to be useful for this pedagogical purpose.
My earlier message in this thread went to some length to do something
similar.

But because we only invite later confusion when the “a value is an
object” false equivalence needs un-learning, I can't let it pass.

-- 
 \            “The idea that He would take his attention away from the |
  `\       universe in order to give me a bicycle with three speeds is |
_o__)  just so unlikely that I can't go along with it.” —Quentin Crisp |
Ben Finney




More information about the Python-list mailing list