Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

Operator &=

Clears the stored integer bits that also occur as zeroes in the mask on the right.

Version: Python 3.14; repository image, production runtime not attested

Syntax

target &= value

Clears the stored integer bits that also occur as zeroes in the mask on the right.

Apply an allowed-bit mask to clear unwanted flags before storing a status word. A one in both operands is required for each surviving result bit.

With a mutable set, the same update computes an in-place intersection. An integer is immutable, so aliases to the original integer continue to denote the previous value.

Bits missing from either operand are cleared in the new integer.

Syntax

target &= value

__iand__, __and__, __rand__ · TypeError

Worked example

mask = 0b1100; mask &= 0b0110
mask → 0b0100

Examples

value = 0b1100
value &= 0b1010
print(value)
print(bin(value))

Result

8
0b1000

Bits missing from either operand are cleared in the new integer.

Sources