all Python 3Sets (set)function
set.difference_update
set theory
Remove from the set the elements found in the others (in-place difference).
Syntax
s.difference_update(*others)
It mutates the set in place and returns None, so assigning the result back to your variable silently replaces the set with None. Elements that were not there in the first place are ignored — no KeyError, unlike remove().
Examples
s = {1, 2, 3, 4}
s.difference_update({2, 4})
print(sorted(s)) # → [1, 3]
See also
Open in the full glossarydocs.python.orgReport an inaccuracy