Account
Categories

Symmetric Difference Operation


Definition:

If you have values from two sets and want only those values that are not common in both sets, you should perform a Symmetric Difference Operation.

It creates a set with only non-common values from both sets.

Syntax:

result = set1 ^ set2
# or
result = set1.symmetric_difference(set2)

Example:

a = {1, 2, 3}
b = {2, 3, 4}

result = a ^ b
print(result)

Output:

Exercise

Perform symmetric difference operation on sets a = {10, 20, 30} and b = {20, 40, 50} using Python.