5 回答
TA贡献1780条经验 获得超4个赞
any
all
or
and
任何
any
True
全
all
True
真值表
+-----------------------------------------+---------+---------+ | | 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 | +-----------------------------------------+---------+---------+
附注1:
回归 True
如果可迭代的任何元素为真。 如果可迭代为空,则返回 False
False
回归 True
如果可迭代的所有元素都是真的( 或者如果可迭代是空的).
True
附注2:
any
all
>>> multiples_of_6 = (not (i % 6) for i in range(1, 10))>>> any(multiples_of_6)True>>> list(multiples_of_6)[False, False, False]
(not (i % 6) for i in range(1, 10))
True
any
multiples_of_6
6
True
multiples_of_6
list(multiples_of_6)
7
, 8
9
.
any(x) and not all(x)
[False, False, False]
print [x[0] != x[1] for x in zip(*d['Drd2'])]
TA贡献1856条经验 获得超11个赞
def any(iterable): for item in iterable: if item: return True return Falsedef all(iterable): for item in iterable: if not item: return False return True
any()
all()
添加回答
举报