Recall & Review
beginner
What does the
difference() method do in Python sets?It returns a new set with elements that are in the first set but not in the second set.
Click to reveal answer
beginner
What is the result of
{1, 2, 3}.difference({2, 3, 4})?The result is
{1} because 1 is only in the first set, not in the second.Click to reveal answer
beginner
What does the
symmetric_difference() method do in Python sets?It returns a new set with elements that are in either of the sets but not in both.
Click to reveal answer
beginner
What is the result of
{1, 2, 3}.symmetric_difference({2, 3, 4})?The result is
{1, 4} because 1 and 4 are in only one of the sets, not both.Click to reveal answer
intermediate
How is symmetric difference different from difference?
Difference gives elements only in the first set. Symmetric difference gives elements in either set but not in both.
Click to reveal answer
What does
{1, 2, 3} - {2, 4} return?✗ Incorrect
The difference removes elements in the second set from the first, so {1, 3} remains.
Which method returns elements in either set but not both?
✗ Incorrect
symmetric_difference() returns elements exclusive to each set, excluding common elements.
What is the output of
{5, 6}.symmetric_difference({6, 7})?✗ Incorrect
Elements 5 and 7 are in only one set each, so they form the symmetric difference.
If
A = {1, 2, 3} and B = {2, 3, 4}, what is A.difference(B)?✗ Incorrect
Only 1 is in A but not in B, so difference returns {1}.
Which operator is equivalent to
symmetric_difference()?✗ Incorrect
The caret (^) operator returns the symmetric difference of two sets.
Explain in your own words the difference between the difference and symmetric difference of two sets.
Think about what elements are left after removing common ones.
You got /3 concepts.
Write a Python code snippet that shows how to find the symmetric difference between two sets and print the result.
Use sets like {1, 2} and {2, 3} to see what changes.
You got /3 concepts.