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

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

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'))

控制台输出:

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/919182.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-16
下一篇2022-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存