In Python 3, is it possible to use short-circuit evaluation in an any
call that doesn't have a for .. in
expression in it?
I know that I can take advantage of short-circuit evaluation in a statement like this:
print('Hello' if True or 3/0 else 'World') # this prints "Hello"
But if I try something similar with any
, I get an exception because the 3/0
is evaluated:
print('Hello' if any([True, 3/0]) else 'World') # this raises an exception
Is there a way I can use any
to do this?