ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: A. 4 3

a[:] creates a new list with three items. Appending to a does not change b.

More Python Programming questions

Exams that ask this topic