每天CookBook之Python-031
- 使用strip、lstrip、rstrip替换空格
- 使用正则表达式替换换行
import re
s = ' hello world \n'
print(s.strip())
print(s.lstrip())
print(s.rstrip())
t = '-----hello====='
print(t.lstrip('-'))
print(t.strip('-='))
s = ' hello world \n'
s = s.strip()
print(s)
print(s.replace(' ', ''))
print(re.sub('\s+', ' ', s))
hello world
hello world
hello world
hello=====
hello
hello world
helloworld
hello world