difference_update() function in python by R4R Team

- 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)


output-

{1, 2, 3}
{4, 5, 6}
{5, 6}


-In this program, we have two set {1,2,3,4} & {4,5,6} and we find the set1.difference_update(set2) which update the set1 and put the difference inside it.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!