Python Glossary Русский

all Python 3Sets (set)function

set.symmetric_difference_update

set theory

Update the set to elements in exactly one of the sets (in-place symmetric difference).

Syntax

s.symmetric_difference_update(other)

The operator form is ^=, but it insists on a set on the right-hand side, whereas the method happily takes any iterable — a list, a tuple, a generator. It mutates in place and returns None, so s = s.symmetric_difference_update(other) leaves None in the variable instead of the result; use symmetric_difference when you want a fresh set.

Examples

s = {1, 2, 3}
s.symmetric_difference_update({3, 4})
print(sorted(s))   # → [1, 2, 4]

See also

Open in the full glossarydocs.python.orgReport an inaccuracy