anything like C++ references?

Martin v. Löwis martin at v.loewis.de
Sun Jul 13 18:17:19 EDT 2003


Stephen Horne <intentionally at blank.co.uk> writes:

> 1.  Why are dictionarys called dictionaries (rather than references to
> dictionarys or whatever)? Similar for lists and class instances.

Because they are the values themselves, instead of being references to
values. These values (like all other values) are objects, though,
which means they have identity, state, and behaviour.

You might be thinking of values which only have state and
behaviour. Such values are not supported in Python - objects always
have an identity.

> 2.  Why are the values of mutable objects always forced to be accessed
> via a pointer (or reference or whatever)?

Because all variables are references to objects. In Python, you cannot
have a variable that *is* a value - variables are always *bound* to
values, and accessing the variable yields the associated value. The
values exist independently from the variables they are bound to, and a
single value may be bound to different variables.

> 3.  Why is there no way to reference an immutable object via a
> pointer, other than stuffing it into a mutable object designed for
> some purpose other than simple pointer behaviour?

But there is: If I do

a = 1
b = a

then b *refers* the same value that a refers to. That is, the values
associated with a and b have the same identity.

> This excuse is, as I already said, invalid.

Which excuse? You have only listed questions in this message, not
excuses.

Regards,
Martin




More information about the Python-list mailing list