[英]Why doesn't the "and" condition work in my Python codes?
In python and is a logical AND that returns True if both the operands are true whereas '&' is a bitwise operator.在 python 中,and 是一个逻辑 AND,如果两个操作数都为真,则返回 True,而 '&' 是按位运算符。 I think you are trying to to something like this.
我认为你正在尝试这样的事情。
if (other_list[0] == 0 and rand_vec[0] == 1):
# Do something
Many thanks to Pw Wolf and all others.非常感谢 Pw Wolf 和所有其他人。 Now I understand it.
现在我明白了。
Original code:原始代码:
if (other_list[0] == 0 & rand_vec[0] == 1):
# do something
Improved code:改进的代码:
if (other_list[0] == 0 and rand_vec[0] == 1):
# do something
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.