Symmetric Difference

tags: #python/documentation/sets

How is it different from set difference?

This operation results in a new set containing elements that are unique to either A or B, but not common to both.

The symmetric difference, denoted as AB, represents the elements that are in either set A or set B, but not in both:

Pasted image 20240114000255.png

Example:

set_A = {1, 2, 3, 4, 5}
set_B = {3, 4, 5, 6, 7}

# Symmetric difference (elements in either set_A or set_B, but not in both)
symmetric_difference_result = set_A.symmetric_difference(set_B)
print("Symmetric Difference:", symmetric_difference_result)
Symmetric Difference: {1, 2, 6, 7}
Powered by Forestry.md