Why print (2 > 4 == 4) False in python. Please kindly explain me. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why print (2 > 4 == 4) False in python. Please kindly explain me.

11th Feb 2023, 6:59 PM
TAEK
4 Answers
+ 3
https://www.sololearn.com/discuss/3191192/?ref=app It's already answered in your last question.. If you still have doubt, You can continue ask your doubt in the thread, instead of duplicate. > and == are equal precedence so they evaluated from left to right so first 2 > 4 evaluated it returns false so False == 4 or 0 == 4 is False. False means 0 in int value. Hope it helps...
11th Feb 2023, 7:15 PM
Jayakrishna 🇮🇳
+ 2
2>4 gives false which is not equal to 4 so it is giving you False
11th Feb 2023, 7:13 PM
Bapon Kar
Bapon Kar - avatar
+ 1
The expression 2 > 4 == 4 in Python is evaluated as follows: First, the comparison 2 > 4 is evaluated. This comparison returns False. Next, the comparison False == 4 is evaluated. This comparison returns False. So the final result of the expression 2 > 4 == 4 is False, which is why the code print (2 > 4 == 4) outputs False. It's important to understand the order of operations in such expressions. In this case, the comparison 2 > 4 is evaluated first, and its result (False) is then used in the next comparison False == 4. If the expression had been written as (2 > 4) == 4, it would have raised a SyntaxError, because the comparison 2 > 4 returns a Boolean value of False, which cannot be compared to an integer value of 4.
11th Feb 2023, 7:29 PM
Charuka Madushan Wijethunga
Charuka Madushan Wijethunga - avatar
0
The expression 2 > 4 == 4 in Python is evaluated as follows: First, the comparison 2 > 4 is evaluated. This comparison returns False. Next, the comparison False == 4 is evaluated. This comparison returns False. Because the boolean value False equals with the number 0(zero) and the comparation == operator compare 0==4. Finally, it returns the boolean value False because 0 is not equal to 4.
13th Feb 2023, 7:27 AM
Demissew Getachew
Demissew Getachew - avatar