'is not' or '!='

Ian Kelly ian.g.kelly at gmail.com
Tue Aug 19 12:42:49 EDT 2014


On Tue, Aug 19, 2014 at 7:12 AM, Skip Montanaro <skip at pobox.com> wrote:
> The use of "is" or "is not" is the right thing to do when the object
> of the comparison is known to be a singleton. That is true for None.
> (I suspect it's true for True and False as well, though for historical
> and idiomatic reasons "x is True" is never used.) It would also be
> true if you created a sentinel object like this:
>
> SENTINEL = []

When I need to do this, I use:

    SENTINEL = object()

It's still a singleton, and why should a sentinel be mutable?



More information about the Python-list mailing list