ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
import sys
a = []
b = a
c = [a, a]
print(sys.getrefcount(a) - sys.getrefcount([]) >= 3, c[0] is c[1], [a] == [b])
  1. A. True True True
  2. B. False True True
  3. C. True False True
  4. D. True True False

Correct answer: A. True True True

a is referenced by the names a and b and twice from c, so its reference count is at least 3 higher than that of a temporary empty list. Both slots of c hold the same object, and equal contents make the lists equal.

More Python Programming questions

Exams that ask this topic