ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
t = (1, 2, 3)
t += (4,)
u = t
t *= 2
print(t, u, t is u, len(t) * len(u))
  1. A. (1, 2, 3, 4, 1, 2, 3, 4) (1, 2, 3, 4, 1, 2, 3, 4) False 64
  2. B. (1, 2, 3, 4, 1, 2, 3, 4) (1, 2, 3, 4) True 32
  3. C. (1, 2, 3, 4) (1, 2, 3, 4) False 16
  4. D. (1, 2, 3, 4, 1, 2, 3, 4) (1, 2, 3, 4) False 32

Correct answer: D. (1, 2, 3, 4, 1, 2, 3, 4) (1, 2, 3, 4) False 32

Tuples are immutable, so t *= 2 builds a new tuple and rebinds t, while u keeps the old object. Lists would behave differently because *= changes them in place.

More Python Programming questions

Exams that ask this topic