- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the >> and << operators in Python?
The symbols << and >> are defined as left and right shift operators respectively in Python. They are bitwise operators. First operand is a bitwise representation of numeric object and second is the number of positions by which bit formation is desired to be shifted to left or right.
The << operator shifts bit pattern to left. The least significant bits on right are set to 0
>>> a=60 >>> bin(a) '0b111100' >>> b=a<<2 >>> b 240 >>> bin(b) '0b11110000'
You can see two bits on right set to 0
On the other hand >> operator shifts pattern to right. Most significant bits are set to 0
>>> a=60 >>> bin(a) '0b111100' >>> b=a>>2 >>> b 15 >>> bin(a) '0b111100'
- What are Left Shift and Right Shift Operators (>> and <<) in C#?
- Overloading stream insertion (<<) and extraction (>>) operators in C++
- What is the difference between the != and <> operators in Python?
- Are new HTML5 elements like <section> and <article> useless?
- What is the difference between HTML tags <div> and <span>?
- What is the correct way of using <br>, <br/>, or <br /> in HTML?
- Should I use <img>, <object>, or <embed> for SVG files?
- Why do we use cin >> and cout << in C++ ?
- How to create a valid HTML document with no <html><body> and <head> element?
- What is the usage of <section> and <article> elements? Why they were introduced?
- What is operation of <> in Python?
- What is the difference between >> and >>> operators in Java?
- Selects all <div> elements and all <p> elements with CSS
- What is the operator <=> in MySQL?