首页 / 知识

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

2023-11-12 13:26:00

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

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

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

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

示例:

#!/usr/bin/python3

S="thisisstringexample....wow!!!"

print(S.rstrip())

S="*****thisisstringexample....wow!!!*****"

print(S.rstrip('*'))

输出结果如下:

thisisstringexample....wow!!!

*****thisisstringexample....wow!!!

以上内容为大家介绍了python字符串不要最后字符怎么做?希望对大家有所帮助,如果想要了解更多Python相关知识,请关注我们

培训字符串字符末尾示例

最新内容

相关内容

热门文章

推荐文章

标签云

猜你喜欢