Permanent objects?

Tim Peters tim.one at comcast.net
Tue Dec 24 19:24:05 EST 2002


[Tim]
>> For example, never use "is" to compare immutable objects, unless you
>> don't care what the result is <wink>.  The optimizations can (and do)
>> change across Python releases.

[Dave Brueck]
> Does this also apply to None?

Yes, provided you supply the missing paragraph <wink> about
guaranteed-singleton objects, where "is" is fine.  None and type objects are
guaranteed unique, so "x is None" and "type(d) is dict" are fine (and
idiomatic).  No guarantees about uniqueness are made wrt ints, longs,
floats, complexes, strings, Unicode strings, or tuples.  Uniqueness is
guaranteed for True and False in Python 2.3.





More information about the Python-list mailing list