A.intersection_update(*others) keeps in A only elements that are also present in every supplied iterable. It returns None and modifies the original set in place.
Use intersection() when you want a new set instead of changing the original mutable set.
A={'a','b','c'}
B={'a','y','z'}
A.intersection_update(B)
print(A)
Output
{'a'}
A={'a','b','c'}
B={'a','y','z'}
C={'a','k','l'}
A.intersection_update(B,C)
print(A)
Output
{'a'}
A={'a','b','c','x','y'}
B='Alex'
A.intersection_update(B)
print(A)
Output
{'x'}
Using list with intersection_update() method.
A={'a','b','c'}
B=['a','x','y']
A.intersection_update(B)
print(A)
Output
{'a'}
All Set Methods Updating Set Operations Questions with solutions on set Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.