在Python 3.x中删除字符串中的空格

LJ3*_*LJ3 2 python string python-3.x

我需要转换字符串:

"There are 6 spaces in this string."
Run Code Online (Sandbox Code Playgroud)

至:

"Thereare6spacesinthisstring."
Run Code Online (Sandbox Code Playgroud)

wkl*_*wkl 11

您可以使用 replace

string = "There are 6 spaces in this string"
string = string.replace(' ', '')
Run Code Online (Sandbox Code Playgroud)

  • LJ3:通过单击答案左侧的复选标记以及您认为有用的向上投票答案来接受答案也是一件好事. (5认同)