新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:pythonfor循環(huán)的本質(zhì)探究
1、遍歷可迭代的對象。通過iter()函數(shù)獲得可迭代對象Iterable的迭代器,然后不斷調(diào)用next()方法獲得下一個值。

并將其賦予item值,當(dāng)遇到StopIteration異常時,循環(huán)結(jié)束。
2、遍歷迭代器。循環(huán)迭代器不斷調(diào)用next()方法獲取下一個值。
并將其賦予item值,在遇到StopIteration異常時,循環(huán)結(jié)束。
實例
a = list1.__iter__() #while True: try: i=next(a) print(i) except StopIteration as r: # print('StopIteration') break
以上就是python for循環(huán)的本質(zhì)探究,希望對大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
當(dāng)前題目:創(chuàng)新互聯(lián)Python教程:pythonfor循環(huán)的本質(zhì)探究
轉(zhuǎn)載來源:http://m.5511xx.com/article/dpspdgs.html


咨詢
建站咨詢
