0

I was learning about the precedence of operators and I came across this:

">,>= are binary operators with left-sided binding, and their priority is greater than that shown by == and !=." enter image description here

To verify I wrote the following statement

print(False==0<0) Output: False

But 0<0 gives False and False==False should give True.

Could you tell me where am I going wrong?

Naman Parikh
  • 101
  • 1
  • 1
    Where did you get this table from? – quamrana May 26 '21 at 13:39
  • Where did you find that table? All comparison operators have the same precedence and so the expression is evaluated L to R. (False==0 (true)) < 0 (false). – Nicholas Hunter May 26 '21 at 13:40
  • 2
    "Unlike C, all comparison operations in Python have the same priority, which is lower than that of any arithmetic, shifting or bitwise operation. Also unlike C, expressions like a < b < c have the interpretation that is conventional in mathematics:" "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)." – Carcigenicate May 26 '21 at 13:40
  • @Nicholas This is specifically *not* evaluated as `(False == 0) < 0`…! – deceze May 26 '21 at 13:43
  • Did you get this chart from GeeksForGeeks by chance? That seems like something they'd do. – Carcigenicate May 26 '21 at 13:43
  • @Carcigenicate Thanks! I didn't know about this concept of chaining operators. Now it is clear. I have enrolled in the following course. The chart was given there. https://www.netacad.com/courses/programming/pcap-programming-essentials-python – Naman Parikh May 26 '21 at 13:44

0 Answers0