Python 官方文档:入门教程 => 点击学习
python中使用replace函数进行替换,具体方法如下:replace:replace()函数的作用是把字符串中的old替换成 new。replace()函数语法:str.replace(old, new[, max])参数:old:将
python中使用replace函数进行替换,具体方法如下:
replace:replace()函数的作用是把字符串中的old替换成 new。
replace()函数语法:
str.replace(old, new[, max])
参数:
old:将被替换的子字符串。
new:新字符串,用于替换old子字符串。
max:可选字符串, 替换不超过max次。
replace()函数使用方法:
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
--结束END--
本文标题: python替换用什么函数
本文链接: https://www.lsjlt.com/news/114924.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0