0

Just starting out learning Python. Is the reason for not(True or False) returning False because:

  1. "True or False" is not a Falsy. Hence, not Falsy = Truthy. Therefore, not(Truthy) = False; or

  2. For example, "bag" > "apple" will return True because Python takes the first string to compare, which is "b" and "a" and b is greater than a; therefore, True is returned. Applying the same logic, Python will only take the first statement in (True or False), which would be True and hence, not(True) = False; or

  3. It has something to do with the order of precedence for "not" and "or" operators, which I don't quite grasp and would really appreciate any explanations.

Thank you!

Bill Hileman
  • 2,798
  • 2
  • 17
  • 24
Jay
  • 17

2 Answers2

2

This is the truth table of (a or b) & not (a or b)

enter image description here

As you can see in the 3rd line (on the right) if you take a = True, b = False then the result will be False

ProgrX
  • 111
  • 1
  • 2
  • 15
1

Evaluating the expression in order:

(True or False) = True Due boolean algebra

not (True or False) = not (True) = False As you are negating True so is False

Python interprets True and False as booleans, and in the context of booleans "not", "or", "and" will behave exactly as boolean operators, even if they support other type operands.

Ziur Olpa
  • 1,839
  • 1
  • 12
  • 27
  • do you understand the boolean logic? what would `'hi' or False` return? it should be explained because `or` in Python doesn't return `True` or `False`, it returns the first truthy object or if there is none then the last object while `not` exclusively it the only one that only returns a boolean – Matiiss Mar 17 '22 at 09:37
  • Your are right, but the question types are booleans and in the context of booleans 'or' does return True or False. So boolean algebra still applies for this problem, even if this kind of operations are a subset of the potential behaviour 'or'. I edited my answer thought to clarify it. – Ziur Olpa Mar 17 '22 at 09:52