>> operator in Python

后端 未结 5 1627
无人及你
无人及你 2020-11-30 08:48

What does the >> operator do? For example, what does the following operation 10 >> 1 = 5 do?

5条回答
  •  离开以前
    2020-11-30 09:02

    Its the right shift operator.

    10 in binary is 1010 now >> 1 says to right shift by 1, effectively loosing the least significant bit to give 101, which is 5 represented in binary.

    In effect it divides the number by 2.

提交回复
热议问题