![](/img/trans.png)
[英]Why does this python logic statement behave opposite to my expected behavior?
[英]Python logic if and or opposite
Level = 4
Name = "Mike"
Form = None
if Level == 5 or Name in ['James','Chris','Alex'] or (Name in ['John','Mike'] and Form):
上面的代码完全可以实现我想要的功能,但是我不知道该怎么做:
例如
if Level != 5 and Name not in ['James','Chris','Alex'] and (Name not in ['John','Mike'] and Form):
尽我所能,但无法正常工作。
如何将所有内容都括在括号中,并且一开始就not
使用。 这样,您无需反转任何运算符。
if not (Level == 5 or Name in ['James','Chris','Alex'] or (Name in ['John','Mike'] and Form)):
您的问题有点含糊,据我了解,这应该很简单,
if not (Level == 5 or Name in ['James','Chris','Alex'] or (Name in ['John','Mike'] and Form)):
另一个简单的方法是做这样的事情
if Level == 5 or Name in ['James','Chris','Alex'] or (Name in ['John','Mike'] and Form):
pass
else:
# your code here
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.