why this is true? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

why this is true?

(True > False) == False is false. True > (False == False) is false. why True > False == False is true?

19th Jan 2017, 4:01 AM
ymoon
2 Answers
+ 8
True value is 1, False value is 0 1>0 == false // false.
19th Jan 2017, 5:13 AM
Nahuel
Nahuel - avatar
+ 2
My understanding for the last line is that when Python lets you combine comparison operators like that (WITHOUT using parentheses to make precedence explicit), it's a kind of syntactic sugar. So in Python something like: x > y == z really means: x > y and y == z but the first saves you some typing. And like Nahuel said, True and False behave like 1 and 0. So: >>> print(True > False == False) output: True is because: >>> print(True > False and False == False) output: True As an aside, the one exception to 1 and 0 for True and False is when you convert them to strings. >>> str(True) output: 'True'
19th Jan 2017, 6:20 AM
Potto
Potto - avatar