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.
Arguments
Parameters
| Name | Description |
|---|---|
| *others | One or more sets or iterables containing elements to strip from the set. |
Result
Returns
None, modifies the set in place.
Run it
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)) Output
Press Run to see what it prints.Worth knowing
- In-place operator: The
-=operator performs difference update when both operands are sets.