Python 3 reference · Set Methods

Python Set difference_update() Method

Remove from this set every element found in the others, in place. The same as a -= b.

Python 3 Since 3.0

Syntax

set.difference_update(*others)

Parameters

ParameterDescription
*others One or more iterables.

Return value

None.

Examples

Remove done itemsTry it yourself
todo = {"a", "b", "c"}
todo.difference_update(["b"])
print(sorted(todo))

Output

['a', 'c']
The -= operatorTry it yourself
s = {1, 2, 3}
s -= {1}
print(s)

Output

{2, 3}

Version history

VersionChange
Python 3.0Added