The built-in intersection_update()
method in Python is used to update a set that is calling the method with the elements it has in common with another set.
Figure 1 uses a Venn diagram to represent the intersection of two sets.
x.intersection_update(y)
The intersection_update()
method requires at least one set to be passed as a parameter. However, it is up to the user to choose how many sets to compare.
In addition, it is important to take note of the fact that this method returns None
, and the set that calls the method is simply updated.
#Passing two sets as parametersx = {'Red', 'Blue', 'Purple', 'Orange'}y = {'Yellow', 'Orange', 'Blue', 'Turquoise'}x.intersection_update(y)print(x)
#Passing more than two sets as parametersx = {'Red', 'Blue', 'Purple', 'Orange'}y = {'Yellow', 'Orange', 'Blue', 'Turquoise'}z = {'Cyan', 'Pink', 'Blue', 'Lavender', 'Orange'}x.intersection_update(y,z)print(x)