python字符串不要最后字符怎么做?

2025-12-02 0 87,270

python中可以使用rstrip()方法删除 string 字符串末尾的指定字符(默认为空格)。

rstrip()方法语法:str.rstrip([chars])

chars — 指定删除的字符(默认为空格)

返回值:返回删除 string 字符串末尾的指定字符后生成的新字符串。

示例:

#!/usr/bin/python3
 
S = "     this is string example....wow!!!     "
print (S.rstrip())
S = "*****this is string example....wow!!!*****"
print (S.rstrip('*'))

输出结果如下:

     this is string example….wow!!!

*****this is string example….wow!!!

更多Python知识请关注Python视频教程栏目。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:以上部本文内容由互联网用户自发贡献,本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。投诉邮箱:3758217903@qq.com

ZhiUp资源网 常见问题 python字符串不要最后字符怎么做? https://www.zhiup.top/7164.html

相关