set.difference() in python



"difference()" function is used to find the element which is not common in given two set. It will store the uncommon element by creating a new set.




Syntax:




set.difference(set_value)







Example-1
m = {10, 20, 50}

n = {10, 20, 70}

print(m.difference(n))


Output



{50}







Example-2
m = {10, 20}

n = {10, 20, 50}

print(m.difference(n))


Output



set()







Example-3
n = {10, 50, 10}

m = {10, 20}

n.difference_update(m)

print(n)


Output



{50}