内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

Python中enumerate函數(shù)怎么用-創(chuàng)新互聯(lián)

創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務器提供商,新人活動買多久送多久,劃算不套路!

創(chuàng)新互聯(lián)建站專注于長寧網(wǎng)站建設服務及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供長寧營銷型網(wǎng)站建設,長寧網(wǎng)站制作、長寧網(wǎng)頁設計、長寧網(wǎng)站官網(wǎng)定制、微信小程序開發(fā)服務,打造長寧網(wǎng)絡公司原創(chuàng)品牌,更為您提供長寧網(wǎng)站排名全網(wǎng)營銷落地服務。

小編給大家分享一下Python中enumerate函數(shù)怎么用,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!

enumerate函數(shù)用于遍歷序列中的元素以及它們的下標。

enumerate函數(shù)說明:

函數(shù)原型:enumerate(sequence, [start=0])

功能:將可循環(huán)序列sequence以start開始分別列出序列數(shù)據(jù)和數(shù)據(jù)下標

即對一個可遍歷的數(shù)據(jù)對象(如列表、元組或字符串),enumerate會將該數(shù)據(jù)對象組合為一個索引序列,同時列出數(shù)據(jù)和數(shù)據(jù)下標。

舉例說明:

存在一個sequence,對其使用enumerate將會得到如下結(jié)果:

start        sequence[0]
start+1  sequence[1]
start+2    sequence[2]......

適用版本:

Python2.3+

Python2.x

注意:在python2.6以后新增了start參數(shù)

英文解釋:

Return an enumerate object. sequence must be a sequence, an iterator, or some other object which supports iteration.
 The next() method of the iterator returned by enumerate() returns a tuple containing a count (from start which 
 defaults to 0) and the values obtained from iterating over sequence。

代碼實例:

enumerate參數(shù)為可遍歷的變量,如 字符串,列表等; 返回值為enumerate類。

import string
s = string.ascii_lowercase
e = enumerate(s)
print s
print list(e)

輸出結(jié)果

abcdefghij
[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd'), (4, 'e'), (5, 'f'), (6, 'g'), (7, 'h'), (8, 'i'), (9, 'j')]

在同時需要index和value值的時候可以使用 enumerate。

該實例中,line 是個 string 包含 0 和 1,要把1都找出來:

def xread_line(line):
  return((idx,int(val)) for idx, val in enumerate(line) if val != '0')
  
print read_line('0001110101')
print list(xread_line('0001110101'))

看完了這篇文章,相信你對Python中enumerate函數(shù)怎么用有了一定的了解,想了解更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設公司行業(yè)資訊頻道,感謝各位的閱讀!

本文標題:Python中enumerate函數(shù)怎么用-創(chuàng)新互聯(lián)
文章路徑:http://www.rwnh.cn/article44/dscche.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供云服務器、做網(wǎng)站、網(wǎng)站維護微信小程序、網(wǎng)站營銷、網(wǎng)站建設

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應式網(wǎng)站建設
砚山县| 通化市| 博客| 大余县| 姜堰市| 安陆市| 铜陵市| 惠东县| 巴彦县| 开阳县| 陵水| 齐河县| 三明市| 韶关市| 富裕县| 寿阳县| 育儿| 威信县| 房山区| 黄山市| 宜春市| 兴山县| 仁化县| 宣汉县| 仙游县| 吴江市| 永兴县| 科技| 舒兰市| 巩留县| 平泉县| 浠水县| 桐柏县| 安图县| 荆州市| 徐水县| 阳信县| 横山县| 泊头市| 泾川县| 鸡西市|