Python Collection symmetric_difference_update() Method

Example

Remove items that do not exist in both sets and then insert items that do not exist in both sets:

x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
x.symmetric_difference_update(y) 
print(x)

Run Example

Definition and Usage

The symmetric_difference_update() method updates the original set by removing items that exist in both sets and inserting other items.

Syntax

set.symmetric_difference_update(set)

Parameter Values

Parameters Description
set Required. Used to check matching items in a collection.