Python Set Intersection_Update():

The intersection_update() method updates the source set to reflect the intersection of multiple sets. Hence, the content of original set is modified.

Method signature

The signature for the intersection_update() method is as shown below. Here, the intersection of set A with zero or more sets, given in the parameter, is performed here and the result is stored in set A.


Method parameters and return type

  • The intersection_update() method takes zero or more sets as a parameter. Furthermore, it does not update the set in absence of any parameter.
  • However, It doesn’t return anything.

Python Set intersection_update Examples:

Example 1: In this example, let us take a set A and set B and set C with a set of numbers.

#Initializing the Set
#Printing set A and set B
print("Before set A is ",A)
print("Set B is ",B)
# Using intersection_update 
#Printing a result
print("Updated set A is ",A)
print("Now, set B is ",B)
# If no parameter is passed it doesn't update
#Printing a result
print("No parameter passed in method",C)


Before set A is  {65, 36, 13, 48, 18}
Set B is  {36, 5, 13, 54, 22}
Updated set A is  {36, 13}
Now, set B is  {36, 5, 13, 54, 22}
No parameter passed in method {56, 42, 35}

Example 2: In this case, let us consider a set S containing names of the students nominated for best student of the year. Similarly, Set Comp and Sport contains name of winners in competition and sport. Suppose if we want to find the student who has won medal in both competition and sports. Here, We have to use intersection_update method. Furthermore, if set does not contain an element present in all three, it returns an empty set

#Initializing the Set
S={"Sam", "Jimmy","Tom","Keya","Ram"}
comp={"Ram", "Jimmy", "Keya"}
sport={"Kim", "Sam","Keya", "Tom"}
#Using intersection_update method
#Printing a set
print("Student who secured medal in competition and sport is ",S)


Student who secured medal in competition and sport is {'Keya'}

Example 3: In this example, let us demonstrate the intersection_update() method on a mixed set. Presently, there is no common data elements in set c1 with all the other sets. Hence, intersection_update will update the Set c1 as an empty set.

#Initializing the Set
# Using intersection_update method
# Printing a Set
print ("Result of intersection_update in c1",c1)
print ("Result of intersection_update in c3",c3)


Result of intersection_update in c1 set()
Result of intersection_update in c3 {22}


The intersection_update() method selects the elements that are common with other sets in the parameter and updates the set which calls this method.


Happy Learning 🙂