set.symmetric_difference
Find the items that are in only one of the two collections.
Python 3.13
set.symmetric_difference(other)Parameters
- otherIterable
- The collection to compare with.
Return value
A new set; the originals are not changed.
Examples
Items in exactly one set
Python 3.13
print({1, 2, 3}.symmetric_difference({2, 3, 4})){1, 4}Comparison with a list
Python 3.13
print({1, 2, 3}.symmetric_difference([3, 4, 4])){1, 2, 4}Details
For two sets, the ^ operator does the same.
