Question 12
Back to Exercise
What is the output of the following Python program?
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!