租用问题

质量为本、客户为根、勇于拼搏、务实创新

< 返回租用问题列表

python字符串中间空格如何去除,Python字符串中间加入字符

发布时间:2023-10-31 20:53:03

python字符串中间空格如何去除

可使用replace()函数去除字符串中间的空格,示例以下:

string = "python 字符串 中间 空格"
string = string.replace(" ", "")
print(string)

输出结果为:

python字符串中间空格

在replace()函数中,第一个参数是要替换的字符或字符串,第二个参数是替换为的字符或字符串。在这个例子中,我们将空格字符替换为空字符串,从而去除字符串中间的空格。