ProgrammingModerateGATE CS · Product-company placement

What is printed?

What is printed?
s = {1, 2, 3}
s.add(2)
s.discard(9)
s.update([3, 4], (5,))
r = s.pop() if False else len(s)
try:
    s.remove(9)
except KeyError:
    print("KE", r)
  1. A. KE 5
  2. B. KE 6
  3. C. 5
  4. D. KE 4

Correct answer: A. KE 5

Adding an existing element and discarding a missing one are no-ops; update accepts several iterables, giving {1, 2, 3, 4, 5}. remove (unlike discard) raises KeyError for a missing element.

More Python Programming questions

Exams that ask this topic