1import re
2s = '\n \t this is a string with a lot of whitespace\t'
3s = re.sub('\s+', '', s)
1' hello world! '.strip()
2'hello world!'
3
4
5' hello world! '.lstrip()
6'hello world! '
7
8' hello world! '.rstrip()
9' hello world!'