扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

Python怎么删除字符串中指定的字符

扬州沐宇科技
2023-12-25 11:27:45
python

在Python中删除字符串中指定的字符,可以使用replace()方法来实现。replace()方法接受两个参数,第一个参数是要被替换的字符,第二个参数是替换后的字符。下面是一个例子:

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

输出:

Hello World!

在上面的例子中,我们将字符串中的逗号,替换为空字符串"",从而删除了字符串中的逗号。

扫码添加客服微信