Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

I noticed that I can do things like 2 << 5 to get 64 and 1000 >> 2 to get 250. 

Additionally, I can utilize >> on print

print >>obj, "Hello world"

What's going on here?

1 Answer

0 votes
by (26.4k points)

They are bitwise shift operators

From this docs:

x<<y

  • Returns x with the bits shifted to the left by y places (and new bits on the right-hand-side are zeros). This is the same as multiplying x by 2**y.

x >> y

  • Returns x with the bits shifted to the right by y places. This is the same as dividing x by 2**y

Interested to learn python in detail? Come and Join the python course.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...