ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: D. 4 5 True

|= on a set mutates it in place, so s and t are the same object with four items. | creates a new set, which has five items.

More Python Programming questions

Exams that ask this topic