Is the shortcircuit behaviour of Python's any/all explicit?

后端 未结 4 1554
面向向阳花
面向向阳花 2020-11-28 11:04

Prompted by the discussion here

The docs suggest some equivalent code for the behaviour of all and any

Should the behaviour of the equivalent code be conside

4条回答
  •  独厮守ぢ
    2020-11-28 11:50

    It HAS to short circuit, since it could be given an unbound iterable. If it did not short circuit then this would never terminate:

    any(x == 10 for x in itertools.count())
    

提交回复
热议问题