python 参数个数可变的逻辑运算符
python logical operator with variable number of arguments
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 函数和计数器是可能的。但是想知道有没有更好的方法。
你基本上想要 all()
但要 自定义 你可以使用这个:
def and_function(*args):
return all([a > 5 for a in args])
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 函数和计数器是可能的。但是想知道有没有更好的方法。
你基本上想要 all()
但要 自定义 你可以使用这个:
def and_function(*args):
return all([a > 5 for a in args])