Comparisons and singletons

Steven Watanabe Steven.Watanabe at
Fri Mar 24 21:40:15 CET 2006

PEP 8 says, "Comparisons to singletons like None should always be done
with 'is' or 'is not', never the equality operators." I know that "is"
is an identity operator, "==" and "!=" are the equality operators, but
I'm not sure what other singletons are being referred to here.

Also, I've seen code that does things like:

  if foo is 3:
  if foo is not '':

Are these valid uses of "is"?

Thanks in advance.

More information about the Python-list mailing list