'Why x = 7 < 5 ; print(x) gives false in python? [closed]
x = 7 < 5
print(x)
When I am printing x why its showing false although it should be true?
x = 7 > 5
print(x)
This is True
Solution 1:[1]
You seem to have mixed up the direction of the inequality operators.
When Python sees x = 7 < 5, it finds the truth value of the inequality 7 < 5 and assigns it to x. 7is not less than 5, so the statement 7 < 5 is False. So Python says x = False.
The reverse is true of x = 7 > 5. 7 is greater than 5, so 7 > 5 is True and x = True.
Remember the alligator method: < and > are like a hungry alligator looking for the most food it can eat, so it will point toward the larger value and away from the smaller.
Solution 2:[2]
It should not be true. 7 is not less than 5, and therefore evaluates to False.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | triskofwhaleisland |
| Solution 2 | Lily Smith |
