亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Python enumerate() 函數(shù)如何實現(xiàn)索引功能

 更新時間:2020年06月29日 11:09:06   作者:楊楓哥  
這篇文章主要介紹了Python enumerate() 函數(shù)如何實現(xiàn)索引功能,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

1.描述:

enumerate()函數(shù)用于將一個可遍歷的數(shù)據(jù)對象(如列表,元組,字符串)組合為一個索引序列,同時列出數(shù)據(jù)和數(shù)據(jù)索引(下標),一般用于for循環(huán)當中

2.語法

enumerate(sequence, [start=0])

3.參數(shù):

  • sequence:一個序列,迭代器或其他支持迭代對象
  • start:可選參數(shù),下標起始位置,默認從索引0開始

4.返回值

返回enumerate(枚舉)對象

5.實例

list1 = [10,20,30,40,"maple","yf",60]

tup1 = (100,200,300,400,"hao","qazert",600)

str1 = "1234qwertjdsa22323"

for index1,item1 in enumerate(list1):
  print("index1 = %d, item1 = %s" %(index1,item1,))

print("------------------------------")
for index2, item2 in enumerate(list1,start = 2):
  print("index2 = %d, item2 = %s" %(index2,item2,))

print("******************************")
for index3,item3 in enumerate(tup1):
  print("index3 = %d, item3 = %s" % (index3, item3,))

print("==============================")
for index4,item4 in enumerate(tup1, start = 4):
  print("index4 = %d, item4 = %s" % (index4, item4,))

print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
for index5,item5 in enumerate(str1):
  print("index4 = %d, item4 = %s" % (index5, item5,))

print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
for index6,item6 in enumerate(str1,start = 6):
  print("index4 = %d, item4 = %s" % (index6, item6,))
  
#輸出的結(jié)果如下:
index1 = 0, item1 = 10
index1 = 1, item1 = 20
index1 = 2, item1 = 30
index1 = 3, item1 = 40
index1 = 4, item1 = maple
index1 = 5, item1 = yf
index1 = 6, item1 = 60
------------------------------
index2 = 2, item2 = 10
index2 = 3, item2 = 20
index2 = 4, item2 = 30
index2 = 5, item2 = 40
index2 = 6, item2 = maple
index2 = 7, item2 = yf
index2 = 8, item2 = 60
******************************
index3 = 0, item3 = 100
index3 = 1, item3 = 200
index3 = 2, item3 = 300
index3 = 3, item3 = 400
index3 = 4, item3 = hao
index3 = 5, item3 = qazert
index3 = 6, item3 = 600
==============================
index4 = 4, item4 = 100
index4 = 5, item4 = 200
index4 = 6, item4 = 300
index4 = 7, item4 = 400
index4 = 8, item4 = hao
index4 = 9, item4 = qazert
index4 = 10, item4 = 600
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
index4 = 0, item4 = 1
index4 = 1, item4 = 2
index4 = 2, item4 = 3
index4 = 3, item4 = 4
index4 = 4, item4 = q
index4 = 5, item4 = w
index4 = 6, item4 = e
index4 = 7, item4 = r
index4 = 8, item4 = t
index4 = 9, item4 = j
index4 = 10, item4 = d
index4 = 11, item4 = s
index4 = 12, item4 = a
index4 = 13, item4 = 2
index4 = 14, item4 = 2
index4 = 15, item4 = 3
index4 = 16, item4 = 2
index4 = 17, item4 = 3
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
index4 = 6, item4 = 1
index4 = 7, item4 = 2
index4 = 8, item4 = 3
index4 = 9, item4 = 4
index4 = 10, item4 = q
index4 = 11, item4 = w
index4 = 12, item4 = e
index4 = 13, item4 = r
index4 = 14, item4 = t
index4 = 15, item4 = j
index4 = 16, item4 = d
index4 = 17, item4 = s
index4 = 18, item4 = a
index4 = 19, item4 = 2
index4 = 20, item4 = 2
index4 = 21, item4 = 3
index4 = 22, item4 = 2
index4 = 23, item4 = 3

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 原生python實現(xiàn)knn分類算法

    原生python實現(xiàn)knn分類算法

    這篇文章主要介紹了原生python實現(xiàn)knn分類算法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-10-10
  • 關(guān)于Python中compile() 函數(shù)簡單實用示例詳解

    關(guān)于Python中compile() 函數(shù)簡單實用示例詳解

    這篇文章主要介紹了關(guān)于compile() 函數(shù)簡單實用示例,compile() 函數(shù)將一個字符串編譯為字節(jié)代碼,compile將代碼編譯為代碼對象,應用在代碼中可以提高效率,本文通過示例代碼給大家介紹的非常詳細,需要的朋友可以參考下
    2023-05-05
  • python運用pygame庫實現(xiàn)雙人彈球小游戲

    python運用pygame庫實現(xiàn)雙人彈球小游戲

    這篇文章主要為大家詳細介紹了python運用pygame庫實現(xiàn)雙人彈球小游戲,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • python self,cls,decorator的理解

    python self,cls,decorator的理解

    在python里面,self, cls 不是關(guān)鍵字,完全可以使用自己寫的任意變量代替實現(xiàn)一樣的效果
    2009-07-07
  • Python正則表達式經(jīng)典入門教程

    Python正則表達式經(jīng)典入門教程

    這篇文章主要介紹了Python正則表達式,結(jié)合具體實例形式歸納總結(jié)了Python正則表達式中常用的各種函數(shù)與相關(guān)使用技巧,需要的朋友可以參考下
    2017-05-05
  • 對Python中plt的畫圖函數(shù)詳解

    對Python中plt的畫圖函數(shù)詳解

    今天小編就為大家分享一篇對Python中plt的畫圖函數(shù)詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-11-11
  • Python時間差中seconds和total_seconds的區(qū)別詳解

    Python時間差中seconds和total_seconds的區(qū)別詳解

    今天小編就為大家分享一篇Python時間差中seconds和total_seconds的區(qū)別詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • Python使用unittest進行有效測試的示例詳解

    Python使用unittest進行有效測試的示例詳解

    這篇文章主要介紹了如何使用?unittest?來編寫和運行單元測試,希望通過閱讀本文,大家能了解?unittest?的基本使用方法,以及如何使用?unittest?中的斷言方法和測試用例組織結(jié)構(gòu)
    2023-06-06
  • Python模塊常用四種安裝方式

    Python模塊常用四種安裝方式

    這篇文章主要介紹了Python模塊常用四種安裝方式,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-10-10
  • Python列表的切片實例講解

    Python列表的切片實例講解

    在本篇文章里小編給大家分享了關(guān)于Python列表的切片的知識點實例,需要的朋友們可以參考下。
    2019-08-08

最新評論