python 删除字符串中的空格

来源:互联网 发布:知乎热门话题 编辑:程序博客网 时间:2024/05/17 04:46

1.strip():把头和尾的空格去掉

2.lstrip():把左边的空格去掉

3.rstrip():把右边的空格去掉

4.replace('c1','c2'):把字符串里的c1替换成c2。故可以用replace(' ','')来去掉字符串里的所有空格