<< Left shift
Last updated: 2026-09-22
<< Left shift
<< shifts bits left by n; equivalent to a * (2**n).
| Category | Operators |
|---|---|
| Kind | Operator |
| Python Version | all |
📝 Syntax
a << n
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
16
8
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat does 1 << 10 equal?
A1024. Shifting left by n is equivalent to multiplying by `2**n`: `1 << 4 == 16`, `1 << 10 == 1024`. Python's `int` has no bit-count limit, so left shift does not overflow.
QWhat happens when you left-shift by a negative count?
AIt raises `ValueError: negative shift count`. For right shifts use `>>`, and the shift count must be an integer.
QIs left shift faster than multiplication?
ABit operations are usually a little faster, but the difference is negligible. Prefer readability; do not sacrifice code clarity for such a tiny optimization.