I wish to use the Python all()
function to help me compute something, but this something could take substantially longer if the all()
does not evaluate as soon as it hits a False
. I'm thinking it probably is short-circuit evaluated, but I just wanted to make sure. Also, is there a way to tell in Python how the function gets evaluated?
Because any
and all
are functions, their arguments must be evaluated before they are called. That often creates the impression of no short-circuiting - but they do still short-circuit. To work around the problem, pass a generator expression, or other lazily evaluated expression, rather than a sequence. See Python: Lazy Function Evaluation in any() / all() for details.