intersection_update() function in python by R4R Team

- intersection_update() is a python function which are used to find the intersection of two set and it update the answer in set1.

Syntax-

set1.intersection_update(set2)

Example

set1 is {1,2,3,4}
set2 is {3,4,5,6,7}
intersection_update() update the set1 and put the intersection of both sets inside set1.


program-

set1={1,2,3,4,5,6}
set2={9,8,7,6,5,4,3}

print("Set1 is",set1)
print("Set2 is",set2)

print(set1.intersection_update(set2))
print(set1)
print(set2)


output-

Set1 is {1, 2, 3, 4, 5, 6}
Set2 is {3, 4, 5, 6, 7, 8, 9}
None
{3, 4, 5, 6}
{3, 4, 5, 6, 7, 8, 9}


-In this program, we have two sets and we try to find the intersection of two sets,here set1.intersection_update(set2) will print None value but it update the set1 so we print both set1 and set2 to see the output.




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!