python字符串中间空格如何去除
可以使用replace()函数去除字符串中间的空格,示例如下:
string = "python 字符串 中间 空格"
string = string.replace(" ", "")
print(string)
输出结果为:
python字符串中间空格
在replace()函数中,第一个参数是要替换的字符或字符串,第二个参数是替换为的字符或字符串。在这个例子中,我们将空格字符替换为空字符串,从而去除了字符串中间的空格。
相关问答
可以使用replace()函数去除字符串中间的空格,示例如下:
string = "python 字符串 中间 空格"
string = string.replace(" ", "")
print(string)
输出结果为:
python字符串中间空格
在replace()函数中,第一个参数是要替换的字符或字符串,第二个参数是替换为的字符或字符串。在这个例子中,我们将空格字符替换为空字符串,从而去除了字符串中间的空格。
相关问答
扫码添加客服微信