ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
a = [1, 2]
b = a * 2
b[0] = 9
c = a + a
c[2] = 7
print(a, b, c)
  1. A. [9, 2] [9, 2, 1, 2] [1, 2, 7, 2]
  2. B. [1, 2] [9, 2, 1, 2] [1, 2, 7, 2]
  3. C. [1, 2] [9, 2, 1, 2] [1, 2, 1, 7]
  4. D. [1, 2] [1, 2, 1, 2] [1, 2, 7, 2]

Correct answer: B. [1, 2] [9, 2, 1, 2] [1, 2, 7, 2]

a * 2 and a + a both build new lists, so changing b or c never affects a. Item assignment changes only the list it is applied to, so only b[0] and c[2] change.

More Python Programming questions

Exams that ask this topic