Why Python built in “all” function returns True for empty iterables?

后端 未结 7 834
萌比男神i
萌比男神i 2020-12-05 02:08

I know it has a good reason, but I want to know what reason?

>>> print all([])
True

If all() is intended to check if every item on

7条回答
  •  死守一世寂寞
    2020-12-05 02:56

    This comes from the mathematical logic.

    "everything is true of the elements of the empty set" (http://en.wikipedia.org/wiki/Empty_set)

    See also http://en.wikipedia.org/wiki/Vacuous_truth

提交回复
热议问题