av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

創(chuàng)新互聯(lián)Python教程:Pythonreplace()

python 中的replace()函數(shù)有助于在用“new”子字符串替換“old”子字符串后返回原始字符串的副本。該函數(shù)還允許指定舊字符串需要替換的次數(shù)。

夏河ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)建站的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!

 **str.replace(old, new [, count]) ** #where old & new are strings 

替換()參數(shù):

replace()函數(shù)接受三個(gè)參數(shù)。如果沒有給定 count 參數(shù),replace()方法將用新的子字符串替換所有舊的子字符串。replace()方法也可以與數(shù)字和符號(hào)一起使用。

參數(shù) 描述 必需/可選
老的 要替換的舊子字符串 需要
新的 將替換舊子串的新子串 可選擇的
數(shù)數(shù) 希望用新的子字符串替換舊的子字符串的次數(shù) 可選擇的

替換()返回值

返回值始終是替換后的新字符串。此方法執(zhí)行區(qū)分大小寫的搜索。如果找不到指定的舊字符串,它將返回原始字符串。

| 投入 | 返回值 | | 線 | 字符串(舊的替換為新的) |

Python 中替換()方法的示例

示例 1:如何在 Python 中使用replace()?

 string = 'Hii,Hii how are you'

# replacing 'Hii' with 'friends'
print(string.replace('Hii', 'friends'))

string = 'Hii, Hii how are you, Hii how are you, Hii'

# replacing only two occurences of 'Hii'
print(string.replace('Hii', "friends", 2)) 

輸出:

 friends,friends how are you
Hii, friends how are you, friends how are you, Hii 

示例 Python 中replace()的工作原理

 string = 'Hii,Hii how are you'

# returns copy of the original string because of count zero
print(string.replace('Hii', 'friends',0))

string = 'Hii, Hii how are you, Hii how are you, Hii'

# returns copy of the original string because old string not found
print(string.replace('fine', "friends", 2)) 

輸出:

 Hii,Hii how are you
Hii, Hii how are you, Hii how are you, Hii 

標(biāo)題名稱:創(chuàng)新互聯(lián)Python教程:Pythonreplace()
文章鏈接:http://uogjgqi.cn/article/djpsheo.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們?cè)谖⑿派?4小時(shí)期待你的聲音

解答本文疑問/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流