Search code examples
pythonpython-3.xmath

`3 > 2 == True` returns False?


I tried an expression on my notebook cell

3 > 2 == True

and the output is False ?


Solution

  • This is called chained comparison.

    From the docs: Comparisons

    Comparisons can be chained arbitrarily, e.g., x < y <= z is equivalent to x < y and y <= z, except that y is evaluated only once (but in both cases z is not evaluated at all when x < y is found to be false).

    So the equation becomes:

    3 > 2  and 2 == True
    True and False
    False