Question-47
python
sets
DA-2025
Consider the following Python code snippet.
When the program is executed, at the end, which of the following sets contains “this”?
NoteAnswer
NoteSolution
A few points to note.
- The operator \(\displaystyle |\) is the union operator.
- The operator \(\displaystyle -\) is the difference operator.
- In the assignment statement
A, B, C = A - B, B - C, C - A, the right hand side is evaluated first and it is packed into a tuple. The tuple is then unpacked intoA, B, C.
Now it is a question of executing the loop and checking for the conditions.
- Loop-1
- After the first
if,A = {"this"}, B = {"that"}, C = {"other"} - After the second
if,A = {"this", "other"}, B = {"that", "this"}, C = {"other", "that"}
- After the first
- Loop-2
- After the first
if,A = {"other"}, B = {"this"}, C = {"that"}
- After the first
Since "that" is not in B and "other" not in C, we exit the loop. Only B has "this".