python replace

python中Replace函数如何使用

小亿
214
2023-09-07 16:58:28
栏目: 编程语言

Python中的replace函数用于将字符串中的指定子字符串替换为另一个字符串。

基本语法如下:

string.replace(old, new, count)

参数说明:

示例:

string = "Hello, World!"
new_string = string.replace("Hello", "Hi")
print(new_string)

输出结果为:

Hi, World!

注意:replace函数返回一个新的字符串,原字符串不会被修改。

0
看了该问题的人还看了