一,方法一 repalce方法 space_str = 'a b c' cur_str = space_str.replace(' ', '') print(cur_str) # cur_str: abc 二,方法二 split和join方法 space_str = 'a b c' cur_str = "".join(space_str.split()) print(cur_str) # cur_str: abc