1>>> import re
2>>> re.sub(' +', ' ', 'The quick brown fox')
3'The quick brown fox'
1a = " yo! "
2b = a.strip() # this will remove the white spaces that are leading and trailing
1#If you want to remove LEADING and ENDING spaces, use str.strip():
2
3sentence = ' hello apple'
4sentence.strip()
5>>> 'hello apple'