How to strip all whitespace from string

前端 未结 11 1914
暖寄归人
暖寄归人 2020-11-28 18:25

How do I strip all the spaces in a python string? For example, I want a string like strip my spaces to be turned into stripmyspaces, but I cannot s

11条回答
  •  青春惊慌失措
    2020-11-28 19:03

    Try a regex with re.sub. You can search for all whitespace and replace with an empty string.

    \s in your pattern will match whitespace characters - and not just a space (tabs, newlines, etc). You can read more about it in the manual.

提交回复
热议问题