ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
s = {1, 2}
t = s
t |= {3}
print(s, s is t)
  1. A. {1, 2} True
  2. B. {1, 2, 3} False
  3. C. {3} True
  4. D. {1, 2, 3} True

Correct answer: D. {1, 2, 3} True

|= on a set mutates it in place, and t is the same object as s, so both names show the new element.

More Python Programming questions

Exams that ask this topic