No, interned objects are maintained in a range of locations, no one method exists to list them all.
- Strings can be interned, as you discovered, and you can intern strings yourself by using the
intern()
function. - Small integers between -5 and 256 are interned.
- Tuples are reused; the empty tuple (
()
) is a singleton, and 2000 each of tuple sizes 1 through to 20 are kept cached for recycling. (Just the tuple objects, not the contents). None
is a singleton, as areEllipsis
,NotImplemented
,True
andFalse
.- As of Python 3.3, instance
__dict__
dictionaries can share keys to save on memory. - The compiler can mark immutable (and in certain circumstances, mutable) sourcecode literals as constants, store them as such with the bytecode and re-use them each time the bytecode is run. This applies to strings, numbers, tuples, lists (if used with an
in
statement) and as of Python 3.2 sets (again, when used within
).
There may be more I haven't discovered yet.
These optimizations all help to avoid too much heap churn. And apart from None
, Ellipsis
, NotImplemented
, True
and False
being a singletons they are all CPython-specific optimisations, they are not part of the Python language definition itself.