看板 Python 關於我們 聯絡資訊
例如L=["a","b","c","d","c","f"] for i in L: 我想要在第五個位置的資訊作處理 該如何作比較好呢? 可以改用 i=0 for i in range(len(L)): if i==4 print i 但有更好的方法嗎? 謝謝 -- Sent from my Android -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.251.204.224 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1443111038.A.A18.html ※ 編輯: opengood5566 (111.251.204.224), 09/25/2015 00:14:57
DumDumGenius: 直接 if len(L)>=5:09/25 00:29
DumDumGenius: print L[4] 感覺更快耶09/25 00:29
uranusjr: for i, x in enumerate(L)09/25 01:02
DumDumGenius: 看到三樓 突然覺得慚愧09/25 01:58
tyc5116: 原來可以這樣寫...學到了XD09/25 08:19
※ 編輯: opengood5566 (111.251.204.224), 09/25/2015 22:22:43
s860134: enumerate 是好東西 至少讓你省略掉宣告一個變數XD 09/30 08:59
opengood5566: 感謝^^ 10/20 22:51