Python Set difference() Method

Python Set difference() Method

The set.difference() method in Python returns the set difference of two sets(A-B).

Syntax

Parameter

set- This argument represents a set (minuend)

set1- This arguments represents a set(subtrahend)

Return

This method returns the difference of the two specified sets i.e. the returned set will contain the items that exist only in the first set, and not in both sets.

Example 1

Output

Example 2

Output