查找和替换字符串中的文本

2024-05-21 02:59:31 发布

您现在位置:Python中文网/ 问答频道 /正文

2条回答

您可以使用Python的replace()方法来执行以下操作:

oldUrl = 'https://onion-rip.de/data/images/9d5faef5c26f69546f8/68c8a2a5fe0a9c5c221a2bb.jpg'
newUrl = oldUrl.replace('https://onion-rip.de', 'https://test.de')
print(newUrl)

在下面的示例中使用Python的.replace()

x = "Hello world!"
y = x.replace("Hello", "Bye")
print y #Will print out "Bye World!"

相关问题 更多 >