Python 中的 all() 和 any()
阿新 • • 發佈:2019-01-01
Python 中的 all() 和 any()
轉載請註明出處:https://blog.csdn.net/jpch89/article/details/85119026
文章目錄
1. all()
互動模式下使用 help(all)
檢視幫助文件:
>>> help(all) Help on built-in function all in module builtins: all(iterable, /) Return True if bool(x) is True for all values x in the iterable. If the iterable is empty, return True.
all()
函式接收一個可迭代物件作為引數,不能不傳引數呼叫。- 對可迭代物件中的每個元素
x
都進行布林型別轉換bool(x)
,如果它們都為True
,那麼返回True
,只要有一個為False
,則返回False
。 - 假如可迭代物件為空,返回
True
。
相當於
x1 and x2 and x3 ... and xn
得到的結果
2. any()
互動模式下使用 help(any)
檢視幫助文件:
>>> help(any) 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.
any()
函式接收一個可迭代物件作為引數,不能不傳引數呼叫。- 對可迭代物件中的每個元素
x
都進行布林型別轉換bool(x)
,如果它們都為False
,那麼返回False
,只要有一個為True
,則返回True
。 - 假如可迭代物件為空,返回
False
。
相當於
x1 or x2 or x3 ... or xn
得到的結果
完成於 2018.12.27