這篇“python中替換函數實例分析”文章的知識點大部分人都不太理解,所以小編給大家總結了以下內容,內容詳細,步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“python中替換函數實例分析”文章吧。
具體使用步驟:
1、首先打開python編輯器,新建一個python項目。
2、在python項目中定義一個字符串。
str = "this is string example....wow!!! this is really string";
3、最后再通過replace()函數進行替換字符串即可。
print str.replace("is", "was");
完整示例代碼:
#!/usr/bin/python
#www.xieniao.com
str = "this is string example....wow!!! this is really string";
print str.replace("is", "was");
print str.replace("is", "was", 3);
輸出結果:
thwas was string example....wow!!! thwas was really string
thwas was string example....wow!!! thwas is really string
擴展知識:
strip() #刪除指定字符串函數
re.sub() #通過正則表達式替換
以上就是關于“python中替換函數實例分析”這篇文章的內容,相信大家都有了一定的了解,希望小編分享的內容對大家有幫助,若想了解更多相關的知識內容,請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。