Python collections 判斷實(shí)例是否為可迭代對(duì)象或迭代器
環(huán)境信息
ModelArts
Notebook - pytorch1.4-cuda10.1-cudnn7-ubuntu18.04
JupyterLab - Notebook - Conda-python3
collections 判斷實(shí)例是否為可迭代對(duì)象或迭代器
from collections.abc import Iterable
# 可迭代對(duì)象中需要實(shí)現(xiàn) __iter__ 或者 __getitem__ # list() 是 可迭代對(duì)象嗎? isinstance(list(),Iterable) True
from collections.abc import Iterator
# 迭代器 __iter__ __next__ stopiteration # list()是迭代器嗎? isinstance(list(),Iterator) False
# iter(list())是迭代器嗎? isinstance(iter(list()),Iterator) True
help
help(iter) Help on built-in function iter in module builtins: iter(...) iter(iterable) -> iterator iter(callable, sentinel) -> iterator Get an iterator from an object. In the first form, the argument must supply its own iterator, or be a sequence. In the second form, the callable is called until it returns the sentinel.
help(Iterator) elp on class Iterator in module collections.abc: class Iterator(Iterable) | Method resolution order: | Iterator | Iterable | builtins.object | | Methods defined here: | | __iter__(self) | | __next__(self) | Return the next item from the iterator. When exhausted, raise StopIteration ......
help(Iterable) Help on class Iterable in module collections.abc: class Iterable(builtins.object) | Methods defined here: | | __iter__(self) ......
相關(guān)鏈接
Python入門篇
Python進(jìn)階篇
Python應(yīng)用篇
幫助文檔-AI開(kāi)發(fā)平臺(tái)ModelArts
【生長(zhǎng)吧!Python】有獎(jiǎng)?wù)魑幕馃徇M(jìn)行中
備注
歡迎各位同學(xué)一起來(lái)交流學(xué)習(xí)心得^_^
在線課程、沙箱實(shí)驗(yàn)、認(rèn)證、論壇和直播,其中包含了許多優(yōu)質(zhì)的內(nèi)容,推薦了解與學(xué)習(xí)。
AI開(kāi)發(fā)平臺(tái)ModelArts Python
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請(qǐng)聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時(shí)內(nèi)刪除侵權(quán)內(nèi)容。
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請(qǐng)聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時(shí)內(nèi)刪除侵權(quán)內(nèi)容。