ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
a = [1, 2, 3]
b = a[:]
print(a == b, a is b, a[:] is a[:], id(a) == id(b), a.copy() == list(a))
  1. A. True False True False True
  2. B. True True False True True
  3. C. True False False False True
  4. D. True False False True True

Correct answer: C. True False False False True

Each slice creates a new list object (so `is` comparisons are False) with equal contents. Two lists alive at the same time have different ids.

More Python Programming questions

Exams that ask this topic