python中的any和all函数

 

  any和all函数是判断一组数据真假性的综合结果。以下摘选自Stackoverflow

------------------ 分割线开始 -----------------

any

any will return True when at least one of the elements is Truthy. Read about Truth Value Testing.

all

all will return True only when all the elements are Truthy.

Truth table

+-----------------------------------------+---------+---------+
|                                         |   any   |   all   |
+-----------------------------------------+---------+---------+
| All Truthy values                       |  True   |  True   |
+-----------------------------------------+---------+---------+
| All Falsy values                        |  False  |  False  |
+-----------------------------------------+---------+---------+
| One Truthy value (all others are Falsy) |  True   |  False  |
+-----------------------------------------+---------+---------+
| One Falsy value (all others are Truthy) |  True   |  False  |
+-----------------------------------------+---------+---------+
| Empty Iterable                          |  False  |  True   |
+-----------------------------------------+---------+---------+

------------------ 分割线结束 -----------------

 

用自己的话总结下来,就是

any至少一个成员为真时返回True,否则返回False,因此空参数返回False;

all全部成员都不为假时返回True,否则返回False,因此空参数返回True。

 

posted @ 2019-01-08 11:33  tlz888  阅读(293)  评论(0编辑  收藏  举报