python any and all function

1 any

如果iterable object至少有一个元素是true的时候,返回为true。空的iterable object返回为false。

2 all

如果iterable object中的每个元素都是true的时候返回true,空的iterable object也返回true。

3 什么叫iterable object的元素是true

python的所有对象都是有true和false的。满足下面条件的object是false,其余的都是true。

  • None

  • False

  • zero of any numeric type, for example, 0, 0L, 0.0, 0j.

  • any empty sequence, for example, '', (), [].

  • any empty mapping, for example, {}.

  • instances of user-defined classes, if the class defines a __nonzero__() or __len__() method, when that method returns the integer zero or bool value False. [1]

原文地址:https://www.cnblogs.com/hustdc/p/7531577.html