简体   繁体   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):

The above code does exactly what I want it to do, but I can't figure out how to do the opposite: 上面的代码完全可以实现我想要的功能,但是我不知道该怎么做:

eg 例如

if Level != 5 and Name not in ['James','Chris','Alex'] and (Name not in ['John','Mike'] and Form):

As close as I got but does not work the same. 尽我所能,但无法正常工作。

How about clubbing everything in parenthesis and just use not in the beginning. 如何将所有内容都括在括号中,并且一开始就not使用。 That way, you don't need to reverse any operator. 这样,您无需反转任何运算符。

if not (Level == 5 or Name in ['James','Chris','Alex'] or (Name in ['John','Mike'] and Form)):

Your question is a bit vague, As far as i understand it should be pretty simple, 您的问题有点含糊,据我了解,这应该很简单,

if not (Level == 5 or Name in ['James','Chris','Alex'] or (Name in ['John','Mike'] and Form)):

another easy way would be to do something like this 另一个简单的方法是做这样的事情

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