Seemingly odd 'is' comparison.

Terry Reedy tjreedy at
Tue Feb 19 03:45:35 CET 2008

"Asun Friere" <afriere at> wrote in message 
news:8cafcd9e-6a61-483f-b8f3-6e7b0e5ab435 at
| On Feb 19, 9:44 am, Steven D'Aprano <st... at REMOVE-THIS-
|> wrote:
| > Except for documented singletons such as modules and None, which 
| > have the same identity is platform dependent, version dependent, and 
| > dependent on the execution history of your code.
| The advice not to identity test strings and numbers (since they are
| interred in the main implementation),

They may or may not be.  But for almost all purposes, that is irrelevant.

| or tuples, since they  potentially could be, seems sound enough.

Ditto for tuples, unless possibly when they have mutable members.

|  But given the nature of
| immutables, is the identity of these even potentially implementation
| dependant (ie. they couldn't be interred could they)?

The word is 'interned', not 'interred' (buried).

| One might
| conceivably want to know that a list into which one is about to stuff
| something is the same (or perhaps not the same) list as that pointed
| to by another name, which operation, hopefully, remains possible
| across the range of potential implementations.

Lists are mutable, and identity is often important.  Id(list) can be used 
to debug or solve puzzling behavior.


More information about the Python-list mailing list