ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
t = (1, 2)
t += (3,)
print(t, len(t))
  1. A. (1, 2) 2
  2. B. (1, 2, 3) 3
  3. C. (1, 2, 3) 2
  4. D. [1, 2, 4] 3

Correct answer: B. (1, 2, 3) 3

Tuples are immutable, so += builds a new tuple and rebinds t. The new tuple has three items.

More Python Programming questions

Exams that ask this topic