ProgrammingHardTCS NQT · Wipro pattern

What is printed?

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

Correct answer: A. (1, [2, 3])

A tuple cannot be reassigned in place, but the list inside it is mutable, so appending to it changes the tuple's visible contents.

More Python Programming questions

Exams that ask this topic