set.intersection_update() in python



"intersection_update()" function is used to update the element which is common in the given two set. It will store it in the specified set.




Syntax:




set.intersection_update(set_values)







Example-1
n = {10, 30, 50}

m = {10, 30, 100}

n.intersection_update(m)

print(n)


Output



{10, 30}







Example-2
n = {10, 30, 50}

m = {20, 40, 100}

n.intersection_update(m)

print(n)


Output



set()







Example-3
n = {"A", "B", "C"}

m = {"A", "B", "D"}

n.intersection_update(m)

print(n)


Output



{'A', 'B'}