0

In Python, True or -1 > None returns True but True > None and -1 > None returns False???

Why is this?

martineau
  • 119,623
  • 25
  • 170
  • 301
  • 3
    You can't do `a or b > c` to check if either `a` or `b` is greater than `c`. The first code snippet is evaluated as `(True) or (-1 > None)` and since `True` is true, the expression is also true. – Arc676 Jun 18 '17 at 03:08
  • 2
    You are using Python 2. This is a bad idea. Such comparisons work differently in Python 3 which you probably should be using. – Asclepius Jun 18 '17 at 03:09
  • 2
    `True > None` and `-1 > None` both return `True` in `2.7`. – Matthew Moisen Jun 18 '17 at 03:09

1 Answers1

0

In Python, True or -1 > None evaluates as True or (-1 > None), which is always True, regardless of the expression

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245