Reference

Marko Rauhamaa marko at pacujo.net
Mon Mar 3 23:22:55 CET 2014


Jerry Hill <malaclypse2 at gmail.com>:

> except for the fact that there has been 20 years of custom saying that
> comparing to None with equality is wrong.

"if foo == None" is not wrong in any manner. It's just that if you are
comfortable with the "is" operator and its semantics, "if foo is None"
is slightly more natural.

You generally use "==" if more than one object could be equal. If you
know there's only one object of the kind, you convey that knowledge by
the use of "is" even when functionally, it doesn't matter.


Marko



More information about the Python-list mailing list