Is any() evaluated lazily?

前端 未结 7 481
别跟我提以往
别跟我提以往 2021-01-18 03:59

I am writing a script in which i have to test numbers against a number of conditions. If any of the conditions are met i want to return True an

7条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-18 04:23

    JoshiRaez is the actual correct answer.

    Here is an example

    a = []
    
    any([True, a[0]])
    

    will fail

    On the other side, using OR (or AND) will not fail since its not a function:

    a = []
    True or a[0]
    

提交回复
热议问题