all(iterable)
return bool(全都 不为''/0
)
any(iterable)
return bool(起码有一个 不为''/0
)
all函数
和 any函数
的 定义?iterable参数
的 数据类型 是否会对函数结果 产生影响?iterable参数
,俩函数的返回结果是否满足 互补 ?all函数
的返回结果进行探究;同时替换 iterable参数
的 数据类型 以探究问题二;any函数
的返回结果进行探究;# coding=utf-8
### list
# char型list
assert all(['a', 'b']) == True
assert all(['a', 'b', '']) == False
# int型list
assert all([1, 2]) == True
assert all([1, 2, 0]) == False
# 混合型list
assert all(['a', 'b', 0]) == False # 不幸地含有 0 或 '' , 只能返回 False 了
assert all([1, 2, '']) == False # 不幸地含有 0 或 '' , 只能返回 False 了
# empty list
assert all([]) == True # 完全不含有 0 或 '' , 可以返回 True
### tuple
# char型list
assert all(('a', 'b')) == True
assert all(('a', 'b', '')) == False
# int型tuple
assert all((1, 2)) == True
assert all((1, 2, 0)) == False
# 混合型tuple
assert all(('a', 'b', 0)) == False
assert all((1, 2, '')) == False
# empty tuple
assert all(()) == True
# coding=utf-8
### list
# char型list
assert any(['a', 'b', '']) == True
assert any(['', '', '']) == False
# int型list
assert any([1, 2, 0]) == True
assert any([0, 0, 0]) == False
# 混合型list
assert any(['a', 'b', 0]) == True
assert any([1, 2, '']) == True
assert any([0, '']) == False # 既不存在 "不为0" ,又不存在 "不为''" ,return False
# empty list
assert any([]) == False # 既不存在 "不为0" ,又不存在 "不为''" ,return False
### tuple
# char型list
assert any(('a', 'b', '')) == True
assert any(('', '', '')) == False
# int型tuple
assert any((1, 2, 0)) == True
assert any((0, 0, 0)) == False
# 混合型tuple
assert any(('a', 'b', 0)) == True
assert any((1, 2, '')) == True
assert any((0, '')) == False
# empty tuple
assert any(()) == False
iterable = [1]
assert all(iterable) == any(iterable)
all函数
:return bool(全都 不为''/0
); any函数
:return bool(起码有一个 不为''/0
) 。iterable参数
的 数据类型 不会 对函数结果 产生影响。iterable参数
,俩函数的返回结果 不 满足互补 。