"is not" operator?

S

sturlamolden

What happens here? Does Python (2.6.5) have an "is not" operator?
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?
 
J

John Krukoff

What happens here? Does Python (2.6.5) have an "is not" operator?

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:
False

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

Robert Kern

What happens here? Does Python (2.6.5) have an "is not" operator?

Yes. From Grammar/Grammar:

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

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
C

Carl Banks

Yes. From Grammar/Grammar:

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


Happy thing, too. I use "is not" a lot more than "is" and am happy to
avoid the extra set of parentheses.


Carl Banks
 
M

MRAB

sturlamolden said:
What happens here? Does Python (2.6.5) have an "is not" operator?

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?
In English the negative comes after the verb (or the auxiliary, if there
is one), so:

x is not y

If you wanted to abbreviate:

x is in y

the natural result would be:

x in y

and the opposite:

x is not in y:

would be abbreviated to:

x not in y

The resulting inconsistency in Python is somewhat unfortunate, but in
practice it's not a problem because:

not y

returns either False or True, and how often would you write:

x is False

or:

x is True

?
 
J

Jack Diederich

In English the negative comes after the verb (or the auxiliary, if there
is one), so:

The right way to think about python syntax is not to consider what is
obvious to an LL(1) compiler, or what makes sense in English, but
rather "what was the obvious way to write an LL(1) syntax if you are a
Dutchman who speaks English?"

Hope-that-clears-things-up-ly,

-Jack
 
T

Tim Leslie

The right way to think about python syntax is not to consider what is
obvious to an LL(1) compiler, or what makes sense in English, but
rather "what was the obvious way to write an LL(1) syntax if you are a
Dutchman who speaks English?"

+1 QOTW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top