ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(1 < 2 < 3 == 3.0 != 4, 1 < 2 > 3, (1 < 2) > 3, 'a' < 'b' < 'a')
  1. A. True True False False
  2. B. True False True False
  3. C. True False False True
  4. D. True False False False

Correct answer: D. True False False False

Comparisons chain, so 1 < 2 < 3 == 3.0 != 4 is True only when every adjacent pair holds. 1 < 2 > 3 needs 2 > 3, which fails, while (1 < 2) > 3 compares True with 3. 'a' < 'b' < 'a' fails at the last step.

More Python Programming questions

Exams that ask this topic