Operators

<< — Left bit shift

For integers, moves bits toward more significant positions and is equivalent to multiplication by 2**count for a nonnegative count. Python ints are not fixed-width machine words, so ordinary shifting does not wrap at 32 bits. Negative counts raise ValueError; unsupported operand types raise TypeError. Custom __lshift__ and __rlshift__ can define other behavior. Addition binds more tightly than shifting.

Formal Syntax & Structure

python syntaxpython
left << right

Parameters & Attributes

NameTypeDescription
leftint or supporting objectInteger to shift or supporting object.
rightint or supporting objectNonnegative integer bit count for integer shifting.

Return Value

object

Result selected by the operand types and their operation implementations.

Working Example

Example Snippetpython
print(5 << 2)print(bin(5 << 2))print(-3 << 2)
Python Reference