Python Set symmetric_difference_update() Method
Description
The symmetric_difference_update() method removes elements from the current set that are also present in the other specified set, and inserts elements from the other specified set that are not duplicates into the current set.
Syntax
symmetric_difference_update() method syntax:
set.symmetric_difference_update(set)
Parameters
- set -- The set to be checked
Return Value
None.
Examples
Remove the elements in the original set x that are also present in set y, and insert the elements from y that are not duplicates into set x:
Example 1
x = {"apple", "banana", "cherry"}
y = {"google", "example", "apple"}
x.symmetric_difference_update(y)
print(x)
The output result is:
{'google', 'cherry', 'banana', 'example'}
Python Sets