I’ve always preferred these:
not 'x' in 'abc'
not 'x' is 'a'
(assuming, of course that everyone knows in and is out-prioritize not — I probably should use parentheses) over the more (English) grammatical:
'x' not in 'abc'
'x' is not 'a'
but didn’t bother to think why until I realized they do not make syntactical sense
'x' == not 'a'
'x' not == 'a'
both of course throw a syntax error.
so I figured they were both two-word operators. However, the documentation only references is not and makes no mention of not in as an operator. Am I perhaps misinterpreting the syntax?
If they both are operators, then are they at all different (even subtlety) from their non-grammatical counterparts?
If they are the same, then why do they exist? It seems to be impious to the Zen of Python (..”one — and preferably only one — obvious way”..)
I apologize if this has been discussed to death already, I just had little luck finding it with search terms like “is not”.
From the python 2.6.4 docs at: http://docs.python.org/reference/expressions.html
>
eg: “x not in y” is exactly the same as “not x in y” and “x is not y” is the same as “not x is y”.
“x not == y” doesn’t parse, but “x != y” does, so there’s an equivalence there too …
HTH.