Home >>Python Set Methods >Python Set difference() Method

Python Set difference() Method

Python Set difference() Method

Python set difference() method is used to return a set that contains the difference between two sets.

Syntax:
set.difference(set)

Parameter Values

Parameter Description
set This is a required parameter. It defines the set to check for differences in.
Here is an example of Python difference() method:

x = {"Abhi", "Jerry", "Mickey"}
y = {"Wings", "Alpha", "Jerry"}
z = x.difference(y) 
print(z)

Output:
{'Mickey', 'Abhi'}
Example 2:

y = {"Wings", "Alpha", "Jerry"}
z = y.difference(x) 
print(z)

Output:
{'Alpha', 'Wings'}

No Sidebar ads