Question 14
Back to Exercise
What is the output of the following Python program?
a = {1, 2, 3, 4}
b = a
a &= {2, 4, 6}
a -= {4}
print(a, b, a is b)
- A {2} {1, 2, 3, 4} False
- B {2, 6} {2, 6} True
- C {2, 4} {2, 4} True
- D {2} {2} True Correct
Correct Answer: Option D
&= and -= modify the set in place, so the alias b sees the change.
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!