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

Python Set difference_update() Method

Python Set difference_update() Method

Python3 Lists Python Sets


Description

The difference_update() method removes elements that exist in both sets.

difference_update() The method and the difference() The difference between the methods is that difference() The method returns a new set with the common elements removed, whereas difference_update() The method removes the elements directly in the original set and has no return value.

Syntax

Syntax of the difference_update() method:


set.difference_update(set)

Parameters

Return Value

none.

Example

Remove elements contained in both sets:

Example 1

x

= {

"

apple

"

,

"

banana

"

,

"

cherry

"

}

y

= {

"

google

"

,

"

microsoft

"

,

"

apple

"

}

x

.

difference_update

(

y

)

print

(

x

)

The output is:


{'cherry', 'banana'}

Python3 Lists Python Sets