ProgrammingHardIBM · Deloitte · Product Company SDE

What does the following Python 3 code print? try: a = (1, 2, 3) a[0] = 9 except TypeError: print("TypeError")

  1. A. AttributeError
  2. B. TypeError
  3. C. (9, 2, 3)
  4. D. 9

Correct answer: B. TypeError

Tuples are immutable, so item assignment raises TypeError, which is caught and reported here.

More Python Programming questions

Exams that ask this topic