What do >> and << mean in Python?

后端 未结 7 1829
无人共我
无人共我 2020-12-04 09:44

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

Also I can use >> in pri

7条回答
  •  情书的邮戳
    2020-12-04 10:02

    These are the shift operators

    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 //'ing x by 2**y.

提交回复
热议问题