I have this code in a boolean context:
True and False or 2
Output: 2
The type check for this expression resulted in int.
Next, I modified the code to:
True and False or True
Output : True
And the type check for this expression resulted in bool
2? All you need to know here is the definition of OR operand.Based on python documentation :
The expression x or y first evaluates x; if x is true, its value is returned; otherwise, y is evaluated and the resulting value is returned.
So since the precedence of or is lower than and your expression evaluated as following :
(True and False) or 2
Which is equal to following :
False or 2
Thus based on preceding documentation the result would be the value of right object which is 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With