python中用什么函数去掉空格
lewis
2019-03-17
26次阅读
python中去掉空格的方法有以下几种
1.使用lstrip()函数去掉左边空格
string="*itisblankspacetest*"print(string.lstrip())
输出结果为:
*itisblankspacetest*
2.使用rstrip()函数去掉右边空格
string="*itisblankspacetest*"print(string.rstrip())
输出结果为:
*itisblankspacetest*
3.使用strip()函数去掉左右两边空格
string="*itisblankspacetest*"print(string.strip())
输出结果为:
*itisblankspacetest*
4.使用replace()函数去掉所有空格
string="*itisblankspacetest*"str_new=string.replace("","")printstr_new输出结果为:
*itisblankspacetest

发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。