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

python 3.x上不推荐使用string.replace()。这样做的新方法是什么?

回答:

与2.x中一样,使用str.replace()

例:

>>> 'Hello world'.replace('world', 'Guido')

'Hello Guido'

还要注意,点绑定比字符串伴奏更强,即使用括号:('Hello'+'world')。replace('world','Guido')

以上是 如何在python 3.x中使用string.replace() 的全部内容, 来源链接: utcz.com/qa/406569.html

回到顶部