【发布时间】:2020-03-24 22:51:04
【问题描述】:
我在 python shell 中执行了以下操作。第一个和第三个输出是正确的,但第二个输出是错误的。我知道我可以使用 zip 函数来做到这一点,但我想知道为什么 python 会这样做。
>>> [1,1,1,1] and [1,0,0,0]
[1, 0, 0, 0]
>>> [1,0,0,0] and [1,1,0,0]
[1, 1, 0, 0]
>>> [1,1,1,1] and [0,0,0,0]
[0, 0, 0, 0]
【问题讨论】:
-
谁说你可以这样按位
and?这是stackoverflow.com/questions/47419342/… 的副本 -
我认为是@Georgy,加上逻辑和位运算符之间的混淆。
-
另见Python AND operator on two boolean lists - how?,它直接解决了这个问题
标签: python command-line data-science python-3.7