去掉字符串中间的空格

2018-02-23  本文已影响8人  tengyi

a=' a b c '

1.正则表达式
import re
print(''.join(re.spilt('\s+',a))

  1. 字符串函数replace
    print(a.replace(' ','')

3.字符串函数spilt
print(''.join(a.spilt()))

输出结果'abc'

上一篇 下一篇

猜你喜欢

热点阅读