Skip to content

Question 4

Evaluate:

False and 'a' + 3 or 1 < 2
Solution

Let's work on this from left to right:

False and 'a' + 3:

  • LHS: False
  • RHS: 'a' + 3 \(\Rightarrow\) TypeError

Again, since LHS is already deemed as False, we disregard what the RHS evaluates to and immediately say this whole expression is False (i.e., short-circuiting technique for conditional statements in Python).

False and 'a' + 3 or 1 < 2 \(\Rightarrow\) False or 1 < 2

  • LHS: False
  • RHS: 1 < 2 \(\Rightarrow\) True

For the or operator, once a side of the compound expression is deemed as True, then the whole expression is True. Hence, False or True evaluates to True.

Answer
True