Permanent objects?
Dave Brueck
dave at pythonapocrypha.com
Wed Dec 25 16:00:32 EST 2002
On Tue, 24 Dec 2002, Tim Peters wrote:
> [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.
Good, thanks for that explanation. I just remembered having written "if x
is None" a lot and suddenly worried I was just lucky that it always
worked.
-Dave
More information about the Python-list
mailing list