Actual Use of “>>” and “<<" operators in Python
In this tutorial, We will discuss Use of >> and << in Python.
Those are Bitwise Operators in Python which is called Bitwise left shift and Bitwise right shift.
It is used to Perform Operations On values and variables. It has many Special characters to compute arithmetic and logical operations.
Shift Operators in Python:
The shift operators are used to shift the bits of a number left or right. Then it Multiplies or Dividing the number by two. There are two types of shifting Processes in shifting operators.
- Bitwise Left Shift.
- Bitwise Right Shift.
Use of shift operators (<< and >>) in Python
We will see one by one
Use of Bitwise Left Shift (<<) in Python
The Bitwise Left shift is used to shift the bits of a number to the Left. For that we use the ‘<<‘ left shift symbol. It is used to multiply the number of bits by two respectively.
a = 10 print(a<<1) print(a<<2)
Use of Bitwise Right Shift (>>) in Python
The Bitwise Right Shift is used to shift the bits of a number to Right for that we use ‘>>’ right shift symbol. It is used to divide the number of bits by two respectively.
a = 10 print(a>>1) print(a>>2)
Also read: Python | Binary Operations in NumPy