Python set.symmetric_difference_update() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
set method

Definition

symmetric_difference_update(other) changes the set so that it keeps only the items that were in exactly one of the two collections. An item found in both is removed, and an item found only in other is added.

In other words, it toggles every item of other. It does the same job as symmetric_difference(), but overwrites the original set and returns None.

set.symmetric_difference_update() is an instance method of the built-in set type: call it on a set with dot notation, such as lights_on.symmetric_difference_update(...). No import is needed.

Syntax

Pass exactly one iterable, and call it on its own line, because the return value is always None.

python
s.symmetric_difference_update(iterable)
s ^= other_set
CallWhat it does
{1, 2, 3}.symmetric_difference_update({3, 4})Returns None; the set becomes {1, 2, 4}: 3 is removed and 4 is added.
{1, 2}.symmetric_difference_update([2, 3])Returns None; the set becomes {1, 3}. Any iterable works as the argument.
{1, 2}.symmetric_difference_update({1, 2})Returns None; the set becomes set(), because every item is in both and cancels out.

s ^= other has the same effect, but needs another set on the right. If you must keep the original set, use symmetric_difference() to get a new set.

Method signatures
python
set.symmetric_difference_update(other)
# returns: None; the set now holds the items in exactly one of the set and other
# raises: TypeError unless exactly one iterable is given

Parameters

ParameterDescription
otherOne iterable: set, list, tuple, string, and so on. Repeated items in a list count once, so each item is toggled at most one time.

Return Value

Return ValueDescription
NoneAlways None. The set itself now holds the unshared items; it is empty (set()) if both collections held the same items.

Python Examples

Example 1 — Flip Light Switches on a Control Panel

Items already on are switched off, and new items are switched on, in one call.

python
lights_on = {"hall", "kitchen", "garage"}
flipped = {"kitchen", "attic", "hall"}

print(lights_on.symmetric_difference_update(flipped))
print(sorted(lights_on))

How It Works

  1. Shared items turn off. Hall and kitchen were on and are flipped, so both are removed from the set.
  2. New items turn on. The attic was off, so it is added to the set of lights that are on.
  3. Untouched items stay. The garage was not flipped, so it remains on, and the method itself returns None.

Example 2 — Show That Flipping Twice Restores the Set

Apply the same change two times, then use the ^= operator to cancel everything.

python
selected = {1, 2, 3}
change = [3, 4]

selected.symmetric_difference_update(change)
print(sorted(selected))

selected.symmetric_difference_update(change)
print(sorted(selected))

selected ^= {1, 2, 3}
print(selected)

How It Works

  1. First flip. 3 is in both and is removed, while 4 is new and is added, giving 1, 2, and 4.
  2. Second flip. Applying the same change again removes 4 and brings 3 back, so the set is 1, 2, and 3 once more.
  3. Cancelling with ^=. The operator toggles all of 1, 2, and 3, so every item is removed and Python prints set().

Example 3 — Toggle Seats From a Click Log

Pass a list that repeats an item, then try to pass two iterables.

python
seats = {"A1", "A2"}
clicks = ["A2", "B1", "B1", "B1", "C3"]

seats.symmetric_difference_update(clicks)
print(sorted(seats))

try:
    seats.symmetric_difference_update(["A1"], ["A2"])
except TypeError:
    print("one iterable at a time")

How It Works

  1. Repeats count once. "B1" appears three times in the list but is toggled only once, so it is added a single time.
  2. A2 toggles off. It was already in the set and is in the clicks, so it is removed; A1 is untouched and C3 is added.
  3. Two arguments are rejected. The method accepts one iterable only, so the second call raises TypeError, which is caught and reported.

Frequently Asked Questions

It toggles items: any item found in both collections is removed from the set, and any item found only in the argument is added. It returns None.
symmetric_difference() returns a new set and keeps the original. symmetric_difference_update() changes the original set and returns None.
They have the same effect, but the ^= operator needs a set on the right. The method also accepts a list, tuple, or string.
The argument is treated as a set first, so each item is toggled only once, no matter how often it repeats.
Call it again with the same argument. Every toggled item flips back, so the set returns to its earlier contents.

Next: set.union()

Return a new set with every item from the set and the other iterables.

union() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful