ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
s = {1, 2, 3}
s |= {3, 4}
s.discard(9)
print(sorted(s), 4 in s, len(s))
  1. A. [1, 2, 3, 4] False 4
  2. B. [1, 2, 3] True 3
  3. C. [1, 2, 3, 4] True 3
  4. D. [1, 2, 3, 4] True 4

Correct answer: D. [1, 2, 3, 4] True 4

|= adds 4 to the set, and the duplicate 3 is ignored. discard on a missing item does nothing. The set has four items.

More Python Programming questions

Exams that ask this topic