The symmetric_difference_update() method finds the symmetric difference of two sets (non-similar items of both sets) and updates it to the set that calls the method.
Example
symmetric_difference_update() Syntax
The syntax of the symmetric_difference_update() method is:
A.symmetric_difference_update(B)
Here, A and B are two sets.
symmetric_difference_update() Parameter
The symmetric_difference_update() method takes a single parameter:
- B - a set that pairs with set A to find non-similar items of both sets
symmetric_difference_update() Return Value
The symmetric_difference_update() method doesn't return any value.
Example: Python Set symmetric_difference_update()
Output
Original Set A: {'Python', 'Java', 'Go'}
Updated Set A: {'Java', 'C', 'Go', 'JavaScript'}
In the above example, we have used the symmetric_difference_update() method that returns the set with items that are unique in both sets i.e. it removes similar items (intersection) of the set.
Here, set A is calling the method, so the result is updated to set A. Whereas, the set B remains unchanged.
Recommended Reading: Python Set symmetric difference()