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):
与我接近,但无法正常工作。
答案 0 :(得分:3)
如何将所有内容括在括号中,并在开始时只使用not
。这样,您无需反转任何运算符。
if not (Level == 5 or Name in ['James','Chris','Alex'] or (Name in ['John','Mike'] and Form)):
答案 1 :(得分:0)
您的问题有点含糊,据我了解,这应该很简单,
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