Python删除字符串中空格方法

一,方法一

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

猜你喜欢

转载自blog.csdn.net/m0_47026232/article/details/133527305
今日推荐