Chapters
Python114 chapters

ReferenceSet methods

set.difference()

What is in the first set and not the second.

Signature

a.difference(b) or a - b

Parameters

NameMeans
banother set

Returns

A new set.

Example

Python
before = {"ada", "grace"}
after = {"grace", "kat"}
print("joined:", sorted(after - before))
print("left:", sorted(before - after))

Output

joined: ['kat']
left: ['ada']

See also