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 << rightParameters & Attributes
| Name | Type | Description |
|---|---|---|
| left | int or supporting object | Integer to shift or supporting object. |
| right | int or supporting object | Nonnegative 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)