LearnFrenzy
Sign in Take a free test

Sets · Predict the Output · Question 8

update() versus add() with a tuple Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

What is the output of the following Python program?

main.py
s = {1}
s.update([2, 3], (4,))
s.add((5, 6))
print(len(s), (5, 6) in s, 5 in s)
  • A 6 False True
  • B 5 True False Correct
  • C 7 True True
  • D 5 False True
Correct Answer: Option B

update() adds each element of each iterable (2, 3, 4); add() inserts the tuple (5, 6) as a single element.

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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links