温馨提示×

python字符串怎么去掉指定字符

小亿
110
2023-09-20 15:46:15
栏目: 编程语言

Python中可以使用str.replace()方法来替换字符串中的指定字符。以下是一个示例:

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

在上面的示例中,我们使用replace(",", "")来将字符串中的逗号替换为空字符串,从而去掉了指定的字符。

0