新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python怎樣遍歷字符串
python遍歷字符串的方法:可以直接通過for循環(huán)進(jìn)行遍歷,具體方法如:【strs = 'abcd' for ch in strs: print(ch)】。還可以利用下標(biāo)或迭代器來進(jìn)行遍歷。

可以使用以下幾種方法:
(推薦教程:Python入門教程)
1、直接進(jìn)行遍歷
strs = 'abcd' for ch in strs: print(ch)
2、利用下標(biāo)遍歷
strs = 'abcd' for index, ch in enumerate(strs): print(index,end=' ') print(ch)
3、利用range進(jìn)行遍歷
strs = 'abcd' for index in range(len(strs)): print(strs[index], end=' ')
4、利用迭代器
strs = 'abcd' for ch in iter(strs): print(ch)
網(wǎng)站名稱:創(chuàng)新互聯(lián)Python教程:python怎樣遍歷字符串
網(wǎng)頁URL:http://fisionsoft.com.cn/article/dpodhgj.html


咨詢
建站咨詢
