Back
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?
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