Python 字符串 rstrip() 方法
定义和用法
rstrip()
方法移除字符串末尾的任何尾随字符(字符串末尾的字符),空格是默认的尾随字符。
语法
string.rstrip(characters)
参数值
参数 | 描述 |
---|---|
characters | 可选。要作为尾随字符移除的字符集。 |
更多示例
示例
如果尾随字符是逗号、句号、s、q 或 w,则将其移除。
txt = "banana,,,,,ssqqqww....."
x = txt.rstrip(",.qsw")
print(x)
自己动手试一试 »