【发布时间】:2018-06-15 05:05:52
【问题描述】:
python 中有没有一种方法可以检查逻辑运算符 AND 与可变数量的参数。例如:
def and_function(a,b,c,d,e....):
if a and b and c and d and c and d and e and . and . is True:
return True
我看到使用 *args 函数和使用计数器是可能的。但想知道是否有更好的方法。
【问题讨论】:
-
这样的
and_function已经存在:all()。 -
由于
x and y and z == something模式也相关:How do I test multiple variables against a value? -
这是我试过的代码。