ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
x = [1, 2, 3]
y = x.copy()
y.append(4)
print(len(x), len(y), x is y)
  1. A. 3 4 True
  2. B. 4 4 False
  3. C. 3 4 False
  4. D. 3 3 False

Correct answer: C. 3 4 False

copy makes a new list, so appending to y does not change x. The two names refer to different objects.

More Python Programming questions

Exams that ask this topic