I would like to know how Python evaluates or expressions with integers. Research on the internet has not resulted in satisfactory answers.
Question 1
5<5 or 10
The above results in 10, which I do not understand why.
Question 2
How does :
False or 10
Return 10?
And:
How does :
True or 10 Return True?
Question 3
How does:
5 or 10 Return 5?
EDIT:
Rephrased question:
Why does Python return Boolean (True/False) when true and the Value (5 or 10) when false? I understand that it is a language, but is there a reason why it was mad so?
oris the first non False argument (orFalseif both arguments areFalse)Trueand will return the first one that is, or simply the last one. In your examples ofTrue or 10and5 or 10, bothTrueand5evaluate to True (Falseand0, for example, would be the counter-opposites in this case as both would evaluate to False). Also: Theoroperator evaluates the arguments in the order they're set in, but only if preceding ones fail; the second only gets evaluated if the first isn't True, and so on.