簡體   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