python中的 &和and

113 阅读1分钟
1 & 2
0

1 and 2
2 

在python中 &指的是位运算符 而and是逻辑运算符

1的二进制是01 2的二进制是10  故1 & 2 输出为 0

而当逻辑运算时 1 and 2 故输出为2