Python標準庫:內建函數any(iterable),pythoniterable

來源:互聯網
上載者:User

Python標準庫:內建函數any(iterable),pythoniterable

如果可迭代的對象的所有元素中只要有一個元素為True就返回True,否則返回False。或者可迭代對象為空白,也返回False。這個函數主要用來判斷列表、元組、字典等對象是否有元素為True,提高計算速度,與之等效的代碼如下:

def any(iterable):

    for element in iterable:

        if element:

            return True

    return False

 

例子:

#any()函數a = []b = {}c = (1, 3, 4)d = (None, 1, 3)print('a:', any(a), 'b:', any(b), 'c:', any(c), 'd:', any(d))

輸出結果如下:

a: False b: False c: True d: True


蔡軍生 QQ:9073204  深圳


python有內建函數這個名詞那就說明也有外置函數嘍?

python的內建函數built-in function是指在標準庫standard library中的內建函數。這些函數不屬於任何類或模組,可以直接調用,可以看成python語言不可分割的一部分吧。近似於關鍵字。
abs()
dict()
help()
min()
setattr()

all()
dir()
hex()
next()
slice()

any()
divmod()
id()
object()
sorted()

ascii()
enumerate()
input()
oct()
staticmethod()

bin()
eval()
int()
open()
str()

bool()
exec()
isinstance()
ord()
sum()

bytearray()
filter()
issubclass()
pow()
super()

bytes()
float()
iter()
print()
tuple()

callable()
format()
len()
property()
type()

chr()
frozenset()
list()
range()
vars()

classmethod()
getattr()
locals()
repr()
zip()

compile()
globals()
map()
reversed()
__import__()

complex()
hasattr()
max()
round()

delattr()
hash()
memoryview()
set()

標準庫中其他模組內的靜態方法等不屬於內建函數。

使用者自訂擴充的函數也不屬於內建。
=============
但在其他語言、其他環境下,內建函數的具體含義不同。
內建函數在概念上並沒有唯一專指,是合成詞,最好理解為“被內建了的一些函數”...餘下全文>>
 
python新手才開始看python學習手冊,有沒有必要再搞一本python標準庫??

我也是自學的,今年寒假剛開始,不過我看的是head first python這本書。我感覺先認真看一本比較好吧。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.