Python 3 教程
any() 函數(shù)用于判斷給定的可迭代參數(shù) iterable 是否全部為 False,則返回 False,如果有一個(gè)為 True,則返回 True。
元素除了是 0、空、FALSE 外都算 TRUE。
函數(shù)等價(jià)于:
def any(iterable): for element in iterable: if element: return True return False
Python 2.5 以上版本可用。
以下是 any() 方法的語法:
any(iterable)
如果都為空、0、false,則返回false,如果不都為空、0、false,則返回true。
以下展示了使用 any() 方法的實(shí)例: