set.difference_update() Difference update
Last updated: 2026-09-22
set.difference_update() Difference update
set.difference_update(*others) removes elements found in any of others.
| Category | Set Methods |
|---|---|
| Kind | Built-in Type Method |
| Python Version | all |
📝 Syntax
set.difference_update(*others)
⚙️ Parameters
| others Optional | Zero or more iterables whose elements are removed. |
|---|
Returns:None (removes elements found in any of the others).
Mutates the original:Yes (in place)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
{1, 3}
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat does difference_update() do?
AIt removes in place the elements contained in others, returning None. The opposite of difference(), which returns a new set.
QWhat is the difference from -=?
AEquivalent, but -= requires the right side to be a set; difference_update() accepts any iterable.
QWhat happens when all elements are removed?
AThe set becomes set(), without raising an error.