- difference_update() function is a python in-build function which is applicable on set data type only.
- it work similar as the difference() function of set which find the set difference but difference_update() is also update the set.
Syntax-
set1.difference_update(set2)
- Here set1 and set2 are two set of python and difference_update is find the set difference and update the set1.
Example
set1 is {1,2,3}
set2 is {2,3}
After set1.difference_update(set2), set1 will update and become {1}
program-
set1=set([1,2,3,4])
set2=set([4,5,6])
set1.difference_update(set2)
print(set1)
set1=set([1,2,3,4])
set2=set([4,5,6])
set2.difference_update(set1)
print(set2)
{1, 2, 3}
{4, 5, 6}
{5, 6}