For leading and trailing whitespace:
s = ' foo \t '
print s.strip()
In other cases use a regular expression:
import re
pat = re.compile(r'\s+')
s = ' \t foo \t bar \t '
print pat.sub('', s)
You can use the following video tutorials to clear all your doubts:-