Chapters
Python114 chapters

ReferenceSet methods

set.symmetric_difference()

What is in one set but not both.

Signature

a.symmetric_difference(b) or a ^ b

Parameters

NameMeans
banother set

Returns

A new set.

Example

Python
print(sorted({1, 2, 3} ^ {3, 4}))

Output

[1, 2, 4]

See also