Python Glossary Русский

all Python 3operatorfunction

operator.ilshift

in-place

In-place left shift: a <<= b.

Syntax

operator.ilshift(a, b)

No built-in mutable type supports <<=, so the result always has to be assigned: x = ilshift(x, 1). Python integers never overflow, so a left shift never turns a non-zero number into zero. A negative shift count raises ValueError.

Examples

import operator
print(operator.ilshift(1, 3))   # → 8
print(operator.ilshift(1, 3) == 1 << 3)   # → True
print(operator.ilshift(5, 3), 5 * 2 ** 3)   # → 40 40
print(list(map(operator.ilshift, [1, 2, 3], [4, 3, 2])))   # → [16, 16, 12]
print(operator.ilshift(1, -1))   # → ValueError

See also

Open in the full glossarydocs.python.orgReport an inaccuracy