Python set intersection_update() Method

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.

Set order: sets are unordered. Whenever an example prints a set, the displayed element order can differ between runs or Python environments.
set operation intersection

Using intersection_update() method

A={'a','b','c'}
B={'a','y','z'}
A.intersection_update(B)
print(A)
Output
{'a'}

Using More Than Two Sets

We can use any number of sets with intersection_update()
A={'a','b','c'}
B={'a','y','z'}
C={'a','k','l'}
A.intersection_update(B,C)
print(A)
Output
{'a'}

intersection_update() method

Using string ( iterable object ) with intersection_update() method
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
intersection() union() difference() symmetric_difference()


Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer