intern(string)
Looks for string in a table of interned
strings. If the
string is already present in this table, the already interned copy
of the string is returned. Otherwise, the new string is added to
the table, and then returned.
Interning strings is useful to gain a little performance on dictionary lookup -- if the keys in a dictionary are interned, and the lookup key is interned, the key comparisons (after hashing) can be done by a pointer compare instead of a string compare. Normally, the names used in Python programs are automatically interned, and the dictionaries used to hold module, class or instance attributes have interned keys.
(Changed in version 2.3: Interned strings used to be immortal, but you now need to keep a reference to the interned string around.)