如何在python 3.x中使用string.replace()string.replace()在python 3.x上已弃用。这样做的新方法是什么?
3 回答
MM们
TA贡献1886条经验 获得超2个赞
replace()
是<class 'str'>
python3中的一种方法:
>>> 'hello, world'.replace(',', ':')'hello: world'
慕神8447489
TA贡献1780条经验 获得超1个赞
python 3中的replace()方法简单地用于:
a = "This is the island of istanbul"
print (a.replace("is" , "was" , 3))
#3 is the maximum replacement that can be done in the string#
>>> Thwas was the wasland of istanbul
# Last substring 'is' in istanbul is not replaced by was because maximum of 3 has already been reached
添加回答
举报
0/150
提交
取消