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

标签 python python-3.x string replace

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

最佳答案

在 2.x 中,使用 str.replace() .

例子:

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

关于python - 如何在 python 3.x 中使用 string.replace(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9452108/

相关文章:

string - 给定一个字符串,计算字符串没有重复(和禁止字符)的排列数

python - 对 pandas 数据框进行迭代和平均

python - 在Python字符串中转义 "\"字符[需要避免十六进制编码]

带中断的python嵌套循环

python - 如何在 discord.py 中使命令不区分大小写

python - Python 中包的供应商命名空间

python-3.x - Python 3 .format 和 List

PHP:在不是价格小数点或字符串最后一个字符的第一个句点处拆分字符串

Python:获取和保存屏幕截图的最快方法

vb.net - 替换字符串中的最后一个字符