any
在 Python 3 中,是否可以在没有for .. in
表达式的调用中使用短路评估?
我知道我可以在这样的语句中利用短路评估:
print('Hello' if True or 3/0 else 'World') # this prints "Hello"
但是如果我尝试与 类似的东西any
,我会得到一个异常,因为3/0
被评估:
print('Hello' if any([True, 3/0]) else 'World') # this raises an exception
有没有办法可以any
用来做到这一点?