"is not" operator?

John Krukoff jkrukoff at ltgc.com
Thu Jul 8 16:29:13 EDT 2010


On Thu, 2010-07-08 at 13:10 -0700, sturlamolden wrote:
> What happens here? Does Python (2.6.5) have an "is not" operator?
> 
> >>> a = 5
> >>> print (a is not False)
> True
> >>> print (a is (not False))
> False
> >>> print (not (a is False))
> True
> 
> It seems "y is not x" fits well with spoken English, but it is also a
> bit surprising that "y is not x" does not mean "y is (not x)" but "not
> (y is x)". Why does Python reorder is and not operators, and what are
> the formal rules for this behavior?

Don't forget about the similar "not in", as in:

>>> 'a' not in 'abc'
False

This is probably the section of documentation you want:
http://docs.python.org/reference/expressions.html#notin

-- 
John Krukoff <jkrukoff at ltgc.com>
Land Title Guarantee Company




More information about the Python-list mailing list