a = " a b c " a.replace(" ", "") Out[210]: 'abc'
strip()方法,去除字符串开头或者结尾的空格
a = " a b c " a.strip() Out[212]: 'a b c'