Python Set symmetric_difference_update() Method

The set.symmetric_difference_update() methods updates the set on which the instersection_update() method called, with the elements that are common among the specified sets.

Syntax:

set.symmetric_difference_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.symmetric_difference_update() method.

Example: symmetric_difference_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: symmetric_difference_update() with Multiple Sets
nums = {1, 2, 3, 4, 5}
oddNums = {1, 3, 5, 6, 7, 9}
primeNums = {2, 3, 5, 7}
nums.intersection_update(oddNums, primeNums)
print("Updated set: ", nums)
Output
Updated set: {3, 5}
Want to check how much you know Python?