網(wǎng)站開發(fā)流程包括微信推廣朋友圈廣告
replace()方法
使用方法
str.replace(old, new[, max])
Python replace() 方法把字符串中的 old(舊字符串) 替換成 new(新字符串),如果指定第三個(gè)參數(shù)max,則替換不超過(guò) max 次。
示例
#!/usr/bin/pythonstr = "this is string example....wow!!! this is really string";
print str.replace("is", "was");
print str.replace("is", "was", 3);
#關(guān)于 string 的 replace 方法,需要注意 replace 不會(huì)改變?cè)?string 的內(nèi)容。
temp_str = 'this is a test'
print(temp_str.replace('is','IS'))
print(temp_str)
以上實(shí)例輸出結(jié)果如下:
thwas was string example....wow!!! thwas was really string
thwas was string example....wow!!! thwas is really stringthIS IS a test
this is a test
?
------------------------------------------與正文內(nèi)容無(wú)關(guān)------------------------------------
如果覺(jué)的文章寫對(duì)各位讀者老爺們有幫助的話,麻煩點(diǎn)贊加關(guān)注唄!小弟在這拜謝了!
如果您覺(jué)得我的文章在某些地方寫的不盡人意或者寫的不對(duì),從而讓你對(duì)你人生觀產(chǎn)生顛覆(概不負(fù)責(zé)),需要斧正,麻煩在評(píng)論區(qū)不吝賜教,作者看到后會(huì)根據(jù)您的提示查閱文章進(jìn)行修改,還這世間一個(gè)公理一片藍(lán)天