繁体   English   中英

Python逻辑如果和或相反

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM