Python Set symmetric_difference_update()

Python Set x.symmetric_difference(y) method finds the symmetric difference of the sets x, y; and updates the set x with the resulting set of the operation.

In this tutorial, we will learn the syntax of set.symmetric_difference_update() method and go through examples covering different scenarios for the arguments that we pass to symmetric_difference_update() method.

Syntax

The syntax of set.symmetric_difference_update() method is

set.symmetric_difference_update(other)

where

ParameterDescription
otherA set.
ADVERTISEMENT

Examples

1. Symmetric difference update of x, y

In the following program, we will take two sets: x, y; and find their symmetric difference, and update x with the resulting set.

Python Program

x = {'apple', 'banana', 'cherry'}
y = {'cherry', 'kiwi'}

x.symmetric_difference_update(y)

print(x)
Try Online

Program Output

{'kiwi', 'banana', 'apple'}

Conclusion

In this Python Tutorial, we learned about Python set method symmetric_difference_update(). We have gone through the syntax of symmetric_difference_update() method, and its usage with example programs.