Question 5
Back to Exercise
What is the output of the following Python program?
s = {1, 2}
s.add(2)
s.add(3)
s.discard(10)
print(s, len(s))
- A {1, 2, 2, 3} 4
- B KeyError
- C {1, 2, 3, 10} 4
- D {1, 2, 3} 3 Correct
Correct Answer: Option D
Adding an existing element changes nothing, and discard() ignores a missing one.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!