猿问

如何在python 3.x中使用string.replace()

如何在python 3.x中使用string.replace()

string.replace()在python 3.x上已弃用。这样做的新方法是什么?



慕森卡
浏览 1162回答 3
3回答

MM们

replace()是<class 'str'>python3中的一种方法:>>>&nbsp;'hello,&nbsp;world'.replace(',',&nbsp;':')'hello:&nbsp;world'

慕神8447489

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
随时随地看视频慕课网APP

相关分类

Python
我要回答