LearnFrenzy
Sign in Take a free test

Sets · Predict the Output · Question 12

Set methods with other iterables Answer, explanation & discussion

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

What is the output of the following Python program?

main.py
a = {1, 2}
print(a.union([2, 3]), a.intersection(range(2, 5)), a.difference("12"), a)
  • A {1, 2, 3} {2} {1, 2} {1, 2} Correct
  • B {1, 2, 3} {2} set() {1, 2, 3}
  • C TypeError
  • D {1, 2, 3} {2, 3, 4} {1, 2} {1, 2}
Correct Answer: Option A

Methods accept any iterable. "12" contains the strings "1" and "2", not the ints, so nothing is removed. a itself is unchanged.

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