![图片[1]-python字符串不要最后字符怎么做?-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5eb3787704cc6960.jpg)
python中可以使用rstrip()方法删除 string 字符串末尾的指定字符(默认为空格)。
rstrip()方法语法:str.rstrip([chars])
chars — 指定删除的字符(默认为空格)
返回值:返回删除 string 字符串末尾的指定字符后生成的新字符串。
示例:
#!/usr/bin/python3
S="thisisstringexample....wow!!!"
print(S.rstrip())
S="*****thisisstringexample....wow!!!*****"
print(S.rstrip('*'))
输出结果如下:
原文来自:https://www.py.cnthisisstring example….wow!!!
*****thisisstring example….wow!!!
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END


















































暂无评论内容