Python 3 reference · Set Methods

Python Set intersection_update() Method

Keep only the elements found in this set and all others, in place. The same as a &= b.

Python 3 Since 3.0

Syntax

set.intersection_update(*others)

Parameters

ParameterDescription
*others One or more iterables.

Return value

None.

Examples

Narrow a setTry it yourself
allowed = {"read", "write", "admin"}
allowed.intersection_update({"read", "write"})
print(sorted(allowed))

Output

['read', 'write']
The &= operatorTry it yourself
s = {1, 2, 3}
s &= {2, 3, 4}
print(s)

Output

{2, 3}

Version history

VersionChange
Python 3.0Added