0

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.

4
  • How about thinking in this way: x<=6 is True; not True is False. ? Commented Jan 28, 2020 at 5:18
  • First the mathematical expression will be evaluated , i.e, x<=6 , and then the operator . Here, x<=6 is True . Therefore , negation (not) of True is False. Commented Jan 28, 2020 at 5:21
  • @Austin I think code must be like that: not(x<=6). But in my variant it is: not x. This causes me problem. Commented Jan 28, 2020 at 5:24
  • The 'not' is a Logical operator in Python that will return True if the expression is False. Just like the "!" in java. In your case, x<=6 is True, "not" operator will reverse the result so it will return False. Commented Jan 28, 2020 at 5:25

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.