在Python中删除字符串中的所有空格

风格不统一 提交于 2020-08-08 01:53:18

问题:

I want to eliminate all the whitespace from a string, on both ends, and in between words. 我想消除字符串两端和单词之间的所有空白。

I have this Python code: 我有这个Python代码:

def my_handle(self):
    sentence = ' hello  apple  '
    sentence.strip()

But that only eliminates the whitespace on both sides of the string. 但这仅消除了字符串两侧的空白。 How do I remove all whitespace? 如何删除所有空格?


解决方案:

参考一: https://stackoom.com/question/YhQa/在Python中删除字符串中的所有空格
参考二: https://oldbug.net/q/YhQa/Remove-all-whitespace-in-a-string-in-Python
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!