Python运算符 - 左移

在Python中,左移运算符(<<)用于将一个数字的位向左移动指定的位置数。

✏️ 语法

Python
number << positions

在上面的代码中,number是要移动位的数字,positions是要将位向左移动的位置数。

📘 示例

Python
# 将位向左移动2个位置
number = 5
positions = 2
result = number << positions

print(result)

在上面的代码中,number的值为5,我们将其位向左移动2个位置。