有几种方法可以在Python中删除字符串中的特定字符:
s = "hello, world!" s = s.replace(",", "") # 删除逗号 print(s) # 输出: hello world! s = "hello, world!" s = ''.join([char for char in s if char != ',']) # 删除逗号 print(s) # 输出: hello world! import re s = "hello, world!" s = re.sub(',', '', s) # 删除逗号 print(s) # 输出: hello world! 以上是一些常见的方法,根据具体情况选择最适合您的方法。