Skip to main content

Python: Difference of Sets

The difference between the two sets in Python is equal to the difference between the number of elements in two sets. It returns set which contains items that exist only in the first set, and not in both sets.

Syntax:

set.difference(set)

Parameters:

The set is required to check difference between sets.

Returns:

It returns the difference between two sets which is also a set. 

Examples:

A = {10,20,30,40}
B = {30,40,50,60}
C = A.difference(B)

print(C)

Output: {10, 20}

Tags
Submitted by devanshi.srivastava on July 3, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.