Easy Tutorial
❮ Python Os Renames Python String Encode ❯

Python Set symmetric_difference_update() Method

Python Sets


Description

The symmetric_difference_update() method removes the elements that are present in both the current set and another specified set, and inserts the elements that are not present in both sets into the current set.

Syntax

The syntax for the symmetric_difference_update() method is:

set.symmetric_difference_update(set)

Parameters

Return Value

None.

Example

Remove the elements from the original set x that are also in set y, and insert the elements from set y that are not in set x:

Example 1

x = {"apple", "banana", "cherry"}
y = {"google", "tutorialpro", "apple"}

x.symmetric_difference_update(y)

print(x)

The output is:

{'google', 'cherry', 'banana', 'tutorialpro'}

Python Sets

❮ Python Os Renames Python String Encode ❯