Python Set intersection_update() Method

The set.intersection_update() method updates the set on which the instersection_update() method is called, with common elements among the specified sets.

Syntax:

set.intersection_update(*other_set)

Parameters:

other_set: Required. one or more sets separated by a comma.

Return Value:

No return value.

The following example demonstrates the set.intersection_update() method.

Example: intersection_update()
nums = {1, 2, 3, 4, 5 }
oddNums = {1, 3, 5, 7, 9}
nums.intersection_update(oddNums)
print("Updated set: ", nums)
Output
Updated set:  {1, 3, 5}

The following shows the working of set.intersection_update() method with multiple parameters.

Example: intersection_update()
cities = {'Mumbai','Chicago','Ohio','New York'}
otherCities = {'Ohio','New York','Mumbai','Chicago','Seattle','Philadelphia'}
commonCities = {'Mumbai','Chennai','Bangalore'}
commonCities.intersection_update(cities,otherCities)
print("Updated Set: ", commonCities)
Output
Updated Set:  {'Mumbai'}
Want to check how much you know Python?