Python Set symmetric_difference() Method

Example

Returns a set that contains all items from both sets, but excludes items that exist in both sets:

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

Running Instance

Definition and Usage

The symmetric_difference() method returns a set that contains all items from both sets but does not contain items that exist in both sets.

Meaning: The returned set contains a mixture of items that do not exist in both sets.

Syntax

set.symmetric_difference(set)

Parameter Values

Parameters Description
set Required. Used to check the set of matching items.