ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: A. [1, 2, 3] [9, 2, 3, 1, 2, 3]

Multiplying a list of ints makes a new list with the items repeated, and later item changes do not affect a.

More Python Programming questions

Exams that ask this topic