Python 官方文档:入门教程 => 点击学习
python中去掉空格的方法有以下几种使用lstrip()函数去掉左边空格string = " * it is blank space test&nb
python中去掉空格的方法有以下几种
使用lstrip()函数去掉左边空格
string = " * it is blank space test * "print (string.lstrip())
输出结果为:
* it is blank space test *
使用rstrip()函数去掉右边空格
string = " * it is blank space test * "print (string.rstrip())
输出结果为:
* it is blank space test *
使用strip()函数去掉左右两边空格
string = " * it is blank space test * "print (string.strip())
输出结果为:
* it is blank space test *
使用replace()函数去掉所有空格
string = " * it is blank space test * "str_new = string.replace(" ", "")print str_new
输出结果为:
*itisblankspacetest
--结束END--
本文标题: python中用什么函数去掉空格
本文链接: https://www.lsjlt.com/news/114991.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0