Permanent objects?
Kevin Altis
altis at semi-retired.com
Wed Dec 25 16:40:51 EST 2002
"Dave Brueck" <dave at pythonapocrypha.com> wrote in message
news:mailman.1040847080.15759.python-list at python.org...
> 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.
Hmm, I think I tend to use
if x == None:
and
if x != None:
rather than
if x is None:
and
if not x is None:
I don't suppose it really matters or that one is better or clearer than the
other?
ka
More information about the Python-list
mailing list