Python: Lazy Function Evaluation in any() / all()
问题 Logical operators in Python are lazy. With the following definition: def func(s): print(s) return True calling the or operator >>> func('s') or func('t') 's' only evaluates the first function call, because or recognizes that the expression evaluates to True , irregardless of the return value of the second function call. and does behave analogously. However, when using any() (analogously: all() ) in the following way: >>> any([func('s'), func('t')]) 's' 't' all function calls are evaluated,