Python 3 reference · Set Methods

Python Set symmetric_difference_update() Method

Update the set in place to keep elements in either set but not both. The same as a ^= b.

Python 3 Since 3.0

Syntax

set.symmetric_difference_update(other)

Parameters

ParameterDescription
other An iterable.

Return value

None.

Examples

In placeTry it yourself
s = {1, 2, 3}
s.symmetric_difference_update({3, 4})
print(s)

Output

{1, 2, 4}
Toggle elementsTry it yourself
flags = {"bold"}
flags ^= {"bold"}   # toggle off
flags ^= {"italic"} # toggle on
print(flags)

Output

{'italic'}

Version history

VersionChange
Python 3.0Added