新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python如何replace(替換)多個字符?
python中使用replace替換多個字符的方法:

創(chuàng)新互聯(lián)服務項目包括東明網(wǎng)站建設、東明網(wǎng)站制作、東明網(wǎng)頁制作以及東明網(wǎng)絡營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關系等,向廣大中小型企業(yè)、政府機構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,東明網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務的客戶以成都為中心已經(jīng)輻射到東明省份的部分城市,未來相信會繼續(xù)擴大服務區(qū)域并繼續(xù)獲得客戶的支持與信任!
1、使用replace方法替換多個相連的字符
#!/usr/bin/python
str = "this is string example....wow!!! this is really string";
print str.replace("is", "was");
print str.replace("is", "was", 3);輸出結(jié)果如下:
thwas was string example....wow!!! thwas was really string
thwas was string example....wow!!! thwas is really string
2、在replace()函數(shù)中使用正則替換多個字符
//定義一個數(shù)組 let str = [[1],[2],[3],[4]]; //先轉(zhuǎn)換成JSON字符串 let str2 = JSON.stringify(str); //在對該字符串進行字符替換,在這里我們將所有中括號都替換成空 console.log(str2.replace(/\[|]/g,'')); //這樣就完成了多個字符的替換
網(wǎng)頁題目:創(chuàng)新互聯(lián)Python教程:python如何replace(替換)多個字符?
文章網(wǎng)址:http://m.5511xx.com/article/cdsedhc.html


咨詢
建站咨詢
