easy question on parsing python: "is not None"

Carey Tilden carey.tilden at gmail.com
Thu Aug 5 12:10:53 EDT 2010


On Thu, Aug 5, 2010 at 8:42 AM, wheres pythonmonks
<wherespythonmonks at gmail.com> wrote:
> How does "x is not None" make any sense?  "not x is None" does make sense.
>
> I can only surmise that in this context (preceding is) "not" is not a
> unary right-associative operator, therefore:
>
> x is not None === IS_NOTEQ(X, None)
>
> Beside "not in" which seems to work similarly, is there other
> syntactical sugar like this that I should be aware of?

In addition to all the other fine responses, you also might want to
take a look at the python grammar [1].  The relevant line is:

  comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'

Cheers,
Carey

[1] http://docs.python.org/reference/grammar.html



More information about the Python-list mailing list