Something in the function tutorial confused me.

Neil Cerutti horpner at
Thu Aug 9 17:52:37 CEST 2007

On 2007-08-09, Magnus Lycka <lycka at> wrote:
> It's all a matter of understanding that all the juicy bits in
> the Python data model is in the actual values or objects.
> That's the stuff with type safety, a location in memory,
> qualities such as mutability etc. A "variable" is basically
> just a reference to an arbitrary object in a particular
> namespace.

Excellent post.

Languages like C tried to make the scope of names and the extent
of the objects they refer to be the same, probably for
efficiency.  One nice property of this is that the two concepts
can be conflated into the simpler single idea of "variables".
It's simple, that is, until you create references. Then you can
get into complicated trouble by creating references to things
that may be destroyed. In Python names have lexical scope, while
the objects they refer to are eternal.

> Assignments semantics is not about copying data as in C, and
> it's nothing arbitrarily defined in classes as in C++. It's all
> about deciding which object a name refers to.

Assignment semantics are not arbitrary in C++. You do have to
define them manually for new data types, but if you get it wrong
your code is pretty much useless. You are free to create your own
assignment semantics, as long as they match the semantics of the
built in types. Python has this property as well, though you're
limited to screwing up the "augmented assignment/arithmetic"

Neil Cerutti

More information about the Python-list mailing list