Operators

<<= — Left-shift assignment

Shift a built-in integer left by a nonnegative integer count and rebind the target. For integers this is multiplication by a power of two, without a fixed-width overflow limit. Negative counts raise ValueError. The __ilshift__() 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.
rightnonnegative integer shift countValue used as the right operand of the operation.

Working Example

Example Snippetpython
mask = 0b0011mask <<= 2print(mask)print(bin(mask))
Python Reference