Skip to content
Exercises · Q4

Q.Add a pair of parentheses to each expression so that it evaluates to True.

a) 0 == 1 == 2
b) 2 + 3 == 4 + 5 == 7
c) 1 < -1 == 3 > 4
Yanam CbseNCERTSubjective· 3mImportance★★★★★est
63% · 31/49 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

The trick is that Python's booleans are numbers (False == 0, True == 1): parenthesise an inner comparison so its False/True takes part in the outer arithmetic/comparison — a) 0 == (1 == 2), b) 2 + (3 == 4) + 5 == 7, c) (1 < -1) == (3 > 4).

The idea. Without parentheses these are chained comparisons (0 == 1 == 2 means 0 == 1 and 1 == 2) and all evaluate to False. Parentheses break the chain, and because bool is a subclass of int (False == 0, True == 1), the inner result can be compared or added numerically.

a) 0 == (1 == 2)

StepExpressionValue
11 == 2False
20 == FalseTrue (False equals 0)

b) 2 + (3 == 4) + 5 == 7

StepExpressionValue
13 == 4False (numerically 0)
22 + 0 + 57
37 == 7True

c) (1 < -1) == (3 > 4)

StepExpressionValue
11 < -1False
23 > 4False

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.