Set Methods
difference_update()
Remove elements found in other sets from this set in place.
set.difference_update(*others)
set.difference_update() mutates the calling set in place by removing any element that is also present in any of the others iterables.
Parameters
| Name | Description |
|---|---|
| *others | One or more sets or iterables containing elements to strip from the set. |
Returns
None — modifies the set in place.
Try it
Run it and change it
inventory = {"apple", "banana", "cherry", "date"}
out_of_stock = {"banana", "date"}
inventory.difference_update(out_of_stock)
print(sorted(inventory))Worth knowing
- In-place operator: The
-=operator performs difference update when both operands are sets.