The symmetric_difference_update() function in python first finds out the symmetric-difference of given sets and updates the first set(calling set) with the symmetric-difference values. The symmetric difference means the set of elements that are either in the first set or in the second set. It doesn't contain common elements in the set.
A.symmetric_difference_update(B) #where A & B are sets
The symmetric_difference_update() function takes sets as its parameter. If there are multiple sets, all that will be separated with commas.
Parameter | Description | Required / Optional |
---|---|---|
A & B | The set to check for matches in | Required |
This function doesn't return any value it just updates the calling set with symmetric_difference of two sets. The second set remains unchanged.
X = { 1, 2, 3 }
Y= { 2, 3, 4 }
result = X.symmetric_difference_update(Y)
print('X =', X)
print('Y =', Y)
print('result =', result)
Output:
X = { 1, 4 } Y = { 3, 4, 2 } result = None
X = {'a', 'b', 'c'}
Y = {'b', 'c', 'd' }
result = X.symmetric_difference_update(Y)
print('X =', X)
print('Y =', Y)
print('result =', result)
Output:
A = {'a', 'd'} B = {'d', 'c', 'b'} result = None