ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

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

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

x += x extends the list with its own items, giving four items. x *= 2 doubles that to eight.

More Python Programming questions

Exams that ask this topic