negative numbers are not equal...

Terry Reedy tjreedy at
Thu Aug 14 23:29:18 CEST 2008

When you ask the interpreter to create an immutable object with a 
particular value, it may at its discretion, to conserve space and 
possibly conserve time, return an existing object with that same value. 
   This is documented somewhere in the reference.

The result of comparing two 'different' objects of the same value with 
'is' depends on whether or not the interpreter used that option.  And 
such usage is an implementation and version specific detail.  Aside from 
that, the behavior of two immutable objects with the same value is 
identical to that of two references to the same object.  The benefits of 
the optimization are considered to outweigh the cost of confusing new 
Python programmers ;-)


More information about the Python-list mailing list