1s = ' Hello World From Pankaj \t\n\r\t Hi There '
2
3>>> s.replace(" ", "")
4'HelloWorldFromPankaj\t\n\r\tHiThere'
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!'