Home > Article > Backend Development > How to remove spaces in the middle of Python strings
You can use the replace() function to remove the spaces in the string . The example is as follows:
string = "python 字符串 中间 空格" string = string.replace(" ", "") print(string)
The output result is:
Python字符串中间空格
In the replace() function, the first parameter is the character or string to be replaced, and the second parameter is the character or string to be replaced. In this example, we remove the spaces in the middle of the string by replacing the space characters with an empty string.
The above is the detailed content of How to remove spaces in the middle of Python strings. For more information, please follow other related articles on the PHP Chinese website!