Python 3 内置函数 - any()
函数
0. any()
函数
- 用于判断内容是否全部为空,全部为空则返回 False,否则返回 True.
- 空元素包括:
0
、空
、FALSE
1. 使用方法
>>> help(any)
# output:
Help on built-in function any in module builtins:
## 使用方法:
any(iterable, /)
Return True if bool(x) is True for any x in the iterable.
If the iterable is empty, return False.
2. 使用示例
示例1.
>>> any(['a', 'b', 'c']) # 不为空
# output:
True
示例2.
>>> any(['a', 'b', '']) # 不全部为空
# output:
True
示例3.
>>> any([0, '', False]) # 全部为空
# output:
False
示例4.
>>> any(()) # 空元组
# output:
False