新聞中心
REPLACE替換字符串的時候,需要重新賦值給變量,因為在python中字符串是不可變對象,因此在使用的時候我們必須重新賦值,就這么簡單。Python replace() 方法把字符串中的 old(舊字符串) 替換成 new(新字符串),如果指定第三個參數(shù)max,則替換不超過 max 次。

葫蘆島網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)公司!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項目制作,到程序開發(fā),運營維護。成都創(chuàng)新互聯(lián)公司從2013年成立到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)公司。
replace()方法語法:
str.replace(old, new[, max])
參數(shù)
old -- 將被替換的子字符串。 new -- 新字符串,用于替換old子字符串。 max -- 可選字符串, 替換不超過 max 次
返回值
返回字符串中的 old(舊字符串) 替換成 new(新字符串)后生成的新字符串,如果指定第三個參數(shù)max,則替換不超過 max 次。
以下實例展示了replace()函數(shù)的使用方法:
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
更多學習內(nèi)容,請點擊Python學習網(wǎng)。
分享標題:創(chuàng)新互聯(lián)Python教程:python的replace無法替換怎么辦
地址分享:http://m.5511xx.com/article/coseigp.html


咨詢
建站咨詢
