栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python基础-去掉字符串中的空白字符strip方法

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python基础-去掉字符串中的空白字符strip方法

string1="  123  1234 12 14 hello "
string2="123hello world 123"
"""
string.lstrip()  截掉string左边(开始)的空白字符
string.rstrip()  截掉string右边(开始)的空白字符
string.strip()  截掉string左右两边的空白字符
strip()里面还可以指定截掉的字符串
"""

print(string1.strip())
print(string1.lstrip())
print(string1.rstrip())
print(string2.strip('123'))

控制台输出:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/876340.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号