>>> s="abc efg" >>> ''.join(s.split()) 'abcefg' >>> ''.join(c for c in s if not c.isspace()) 'abcefg' import re s = 'abc efg' re.sub(r's', '', s) => 'abcefg'