检查 AND 条件是否相等的 Pythonic 方法

Hem*_*Sah 1 python

我有一段代码,如下所示:

a = None
b = None
c = None
d = None

if a==None and b==None and c==None and d==None:
    print("All are None")
else:
    print("Someone is not None")
Run Code Online (Sandbox Code Playgroud)

当我有更多数量的变量需要像这样检查时,实现此目的的Pythonic方法或更短的方法是什么?

Qua*_*cha 5

您可以使用列表,并使用列表理解检查列表中的所有项目:

l_list = [None, None, None, None, None]
if all(item is None for item in l_list):
    print("All items are None")
Run Code Online (Sandbox Code Playgroud)