DEV Community

Tommi k Vincent
Tommi k Vincent

Posted on

Difference of Sets in Python

The difference() method returns a set that contains the difference between two sets. The returned set contains items that exist only in the first set, and not in both sets.

Enter the below code into the interactive shell and try to execute it to see the results.

clubs  =set(["Manchester-United","Arsenal","Chelsea","Manchester-City",])

clubsb = set(["Everton","Manchester-United","Liverpool","Totehnam"])


allcubs =  clubs - clubsb
print(allcubs)

Enter fullscreen mode Exit fullscreen mode

When the above code is executed it produces the above result.

{'Chelsea', 'Arsenal', 'Manchester-City'}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)