Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Set symmetric_difference_update() Method

Python Set symmetric_difference_update() Method

Python3 Lists Python Sets


Description

The symmetric_difference_update() method removes elements in the current set that are shared with another specified set, and inserts elements from that other specified set that are different into the current set.

Syntax

Syntax of the symmetric_difference_update() method:



set.symmetric_difference_update(set)

Parameters

Return Value

none.

Example

In the original set x, remove elements duplicated in set y and insert the non-duplicate elements into set x:

Example 1

x

= {

"

apple

"

,

"

banana

"

,

"

cherry

"

}

y

= {

"

google

"

,

"

runoob

"

,

"

apple

"

}

x

.

symmetric_difference_update

(

y

)

print

(

x

)

The output is:



{'google', 'cherry', 'banana', 'runoob'}

Python3 Lists Python Sets