string.replace()
在Python3.x上已弃用。这样做的新方法是什么?
发布于 2012-02-26 17:53:44
发布于 2012-02-26 17:53:27
replace()
是python3中<class 'str'>
的一种方法:
>>> 'hello, world'.replace(',', ':')
'hello: world'
发布于 2017-04-24 23:09:21
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
https://stackoverflow.com/questions/9452108
复制相似问题