+ 1

Why is (17 == True) =False but (if 17: print("yes")) print yes?

19th Mar 2017, 5:48 PM
Ankur Sonawane
Ankur Sonawane - avatar
4 Respuestas
+ 5
You are comparing 17 to true that is equivalent to 17 == 1 and of course results false. in the second if statement there is no comparision so the statement results true.
19th Mar 2017, 6:04 PM
seamiki
seamiki - avatar
+ 1
That is because, internally, True = 1
19th Mar 2017, 5:59 PM
Amaras A
Amaras A - avatar
+ 1
https://docs.python.org/3/library/stdtypes.html#truth-value-testing
19th Mar 2017, 6:06 PM
Mohamed Salah
Mohamed Salah - avatar
0
Because int(True) is 1 and bool(17) is True
19th Mar 2017, 7:35 PM
Nikolai Ivanov
Nikolai Ivanov - avatar