Set Methods

set.difference_update()

Mutates the original set, so aliases observe the change. Remove receiver members found in any supplied iterable. The method accepts iterables rather than requiring set operands. With no arguments, membership is unchanged. Invalid iteration or hashing can raise exceptions. Do not assume transactional rollback on failure. Use the non-mutating counterpart when the original membership must be preserved.

Formal Syntax & Structure

python syntaxpython
items.difference_update(*others)

Parameters & Attributes

NameTypeDescription
othersIterable[Hashable]Zero or more iterables of elements; each iterable is supplied as a separate positional argument.

Return Value

None

Mutates the existing set; no new set is returned.

Working Example

Example Snippetpython
pending = {"build", "test", "ship"}alias = pendingprint(pending.difference_update(["test"], ["ship"]))print(sorted(alias))
Python Reference