[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Names and identifiers

ram at zedat.fu-berlin.de (Stefan Ram):

>   I was asked about the difference between a name and an
>   identifier. I was not sure.

Ah, a delicious terminology debate ahead!

Traditionally, an "identifier" refers to a syntactic (lexical, to be
exact) unit. It is a sequence of Unicode code points inside Python text.
Ultimately, then, an identifier is a string that satisfies some lexical
constraints. For example, the first code point must be a letter.

"Name" is latter-day hypercorrect jargon for a variable. It is an
abstract entity inside the Python runtime engine. It is a memory slot
that can hold a temporal reference to an object.

In Python text, you refer to these memory slots using identifiers
(lists, dicts and tuples have memory slots as well, but I'll leave those
out of this discussion). One identifier can refer to more than one
memory slot. In fact, there is no limit to the number of memory slots
that are referred to using an identical identifier (for example, you
could have a parameter of a recursive function).

>   Shouldn't it say,
> NameError: identifier 'aiuerhguqieh' is not defined

That's an odd way to put it.

>   or even,
> NameError: identifier 'aiuerhguqieh' is not a name

That's better.

Conceptually, every identifier in every context refers to a memory slot.
Only a finite subset of them holds a reference to an object at any given

Or to put it in Python-speak, all names exist, but not all of them are