>>> if id(1) == id(1): print 'OK'
>>> if id(1) == id(2): print 'OK'
Section 5.2.2 (Literals), of the Reference Manual, sez
... Multiple evaluations of literals with the same value (either the
same occurrence in the program text or a different occurrence) may
obtain the same object or a different object with the same value.
(In the original implementation, all literals in the same code block
with the same type and value yield the same object.)
Think that covers everything about that one, right?
The end of Section 3.1 (Objects, values and types) sez
... for immutable types, operations that compute new values may
actually return a reference to any existing object with the same type
and value, while for mutable objects this is not allowed. E.g., after
a = 1; b = 1; c = ; d = 
a and b may or may not refer to the same object with the value one,
depending on the implementation, but c and d are guaranteed to refer
to two different, unique, newly created empty lists.
While the phrase "that compute new values" isn't further defined, I think
its intended meaning is clear enough, and that it would be _un_reasonable
to, e.g., claim that "list" in
a = list
is computing a new value in the intended sense. On the other hand, the
text doesn't explicitly say that the "computing new values" contexts are
the _only_ ones in which an operation yielding an immutable object is
free to return a reference to any object of the same type & value.
So while I eagerly agree it's a real _stretch_ to believe that the
reference manual allows, e.g.,
a = 'immutable object'
x = [a,2]
if x is not a: print 'OUCH'
to print OUCH, I don't think it's a stretch that's definitively forbidden
in the reference manual today (although it's an _unreasonable_ stretch!).
1) If I were Steve, I'd bet Tim's life that no Python implementation will
ever print 'OUCH' without its author(s) agreeing that's a bug.
2) Before Python becomes an international standard, national treasuries
will be drained making every little detail completely clear to jerks
like me <0.9 grin>.
you-may-now-resume-living-ly y'rs - tim
Tim Peters firstname.lastname@example.org
not speaking for Kendall Square Research Corp