Question 2
Evaluate:
Hint
Work out the left-hand side (LHS) and right-hand side (RHS) of the expression. From here, work out the overall statement to obtain the final result.
Solution
LHS: 6 -- 8 < 0 \(\Rightarrow\) 14 < 0 (False)
RHS: 5 % 3 = 2
We now get False or 2, which then evaluates to 2.
Traditionally, if presented with False or True, the natural solution would be to favor True, as the whole expression is True as long as one side of it is.
With the or operator, you take the optimistic approach by favoring the non-False like value if possible.
In this case, 2 is considered a True value/"truthy".
Hence, 2 is favored over False.
Note that the or operator only returns the actual value (i.e., 2) and does not convert the result to True unless explicitly asked.
NOTE:
Like how you take the optimistic approach with the or operator, you take the pessimistic approach with the and operator.
That is, with the pessimistic approach, we favor the False like value.
If we are presented with False and 2, for instance, we will favor False.
Another example: True and [] will produce [].