Python去除空格

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

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

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

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

5.split():通过指定分隔符对字符串进行切片,如果参数num 有指定值,则仅分隔 num 个子字符串

6.使用正则表达式 re.split('\s+',)

猜你喜欢

转载自www.cnblogs.com/dijun/p/9280446.html
今日推荐