ProgrammingHardTCS NQT · Infosys HackWithInfy · Product Company SDE

What does the following Python 3 code print? try: x = [1, 2] + (3, 4) except TypeError: print("TypeError")

  1. A. [1, 2, 3, 4]
  2. B. [1, 2, (3, 4)]
  3. C. TypeError
  4. D. (1, 2, 3, 4)

Correct answer: C. TypeError

The + operator cannot combine a list and a tuple directly; mixing sequence types this way raises TypeError.

More Python Programming questions

Exams that ask this topic