easy question on parsing python: "is not None"

Ben Finney ben+python at benfinney.id.au
Thu Aug 5 11:59:01 EDT 2010


wheres pythonmonks <wherespythonmonks at gmail.com> writes:

> How does "x is not None" make any sense?

In two ways: partly from the fact that Python syntax is preferentially
designed to be reasonably readable to a native English reader; and
partly because it makes for more obvious semantics.

‘is not’ is a single operator which makes operator precedence clear, and
also “x is not None” is gramatically good English.

> "not x is None" does make sense.

It unfortunately makes for awkward English, and it also makes for two
separate operators and hence non-obvious operator precedence.

> I can only surmise that in this context (preceding is) "not" is not a
> unary right-associative operator

Rather than surmise, you can read the language reference
<URL:http://docs.python.org/reference/expressions.html#isnot> which
makes clear that ‘is not’ is one operator.

-- 
 \       “I am amazed, O Wall, that you have not collapsed and fallen, |
  `\            since you must bear the tedious stupidities of so many |
_o__)                  scrawlers.” —anonymous graffiti, Pompeii, 79 CE |
Ben Finney



More information about the Python-list mailing list