Search code examples
pythonargs

python logical operator with variable number of arguments


is there a way in python to check the logical operator AND with variable number of arguments. for example:

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

i see that this is possible using *args function and using a counter. But wish to know if there is a better way of doing it.


Solution

  • You basically want all() but to customize it you can use this:

    def and_function(*args):
        return all([a > 5 for a in args])