Using not in python3

70 Views Asked by At

I am new in python and need help with short code snippet below:

x=5 
print(not x<=6) 

Why the result is False? I think in the next way: not x is False, 0. Then 0 is less than 6. It's True.

1

There are 1 best solutions below

0
On

You have set x equal to 5. This means that when you logically check if x is less than or equal to 6, it will be True. Since you have not there, it cancels the True to make it False, therefore printing False.

I think you may have got your operator precedence mixed up:

<, <=, >, >=, !=, == all take precedence over not