Equality operator

I

italy

Why doesn't this statement execute in Python:

1 == not 0

I get a syntax error, but I don't know why.

Thanks,
Adam Roan
 
K

Kent Johnson

italy said:
Why doesn't this statement execute in Python:

1 == not 0

I get a syntax error, but I don't know why.

Because == has higher precedence than 'not', so you are asking for
(1 == not) 0

Try
 
M

Marek Kubica

Why doesn't this statement execute in Python:

1 == not 0

I get a syntax error, but I don't know why.

This does: 1 == (not 0)
I presume Python treats it like

1 (== not) 0

Which is a SyntaxError

greets,
Marek
 
A

Anthony Boyd

italy said:
Why doesn't this statement execute in Python:

1 == not 0

I get a syntax error, but I don't know why.

Thanks,
Adam Roan

Of course, you would normally want to use != to see if something is not
equal to something else.

1 != 0
True
 
M

Marc 'BlackJack' Rintsch

Why doesn't this statement execute in Python:

1 == not 0

I get a syntax error, but I don't know why.

`==` has a higher precedence than `not` so Python interprets it as::

(1 == not) 0

This works::
True

Ciao,
Marc 'BlackJack' Rintsch
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top