Operators

&= — Bitwise AND assignment

Update an integer with the bitwise intersection of its bits, or a mutable set with the intersection of its elements. This operation evaluates the right operand and is not short-circuiting Boolean and. The __iand__() hook may modify its receiver or supply a replacement. If absent or declining with NotImplemented, normal binary dispatch applies. The result is stored back into the target; this is a statement, not an expression. A failed store does not guarantee rollback.

Formal Syntax & Structure

python syntaxpython
target &= expression

Parameters & Attributes

NameTypeDescription
targetobjectExisting assignable name, attribute, item or slice; its current value participates in the operation.
rightinteger or compatible setValue used as the right operand of the operation.

Working Example

Example Snippetpython
permissions = 0b1110permissions &= 0b0111active = {1, 2, 3}alias = activeactive &= {2, 4}print(permissions)print(sorted(alias))
Python Reference