Python 字符串 rstrip() 方法
实例
删除字符串右边的空格:
txt = " banana "x = txt.rstrip()print("of all fruits", x, "is my favorite")
定义和用法
rstrip() 方法删除所有结尾字符(字符串末尾的字符),空格是要删除的默认结尾字符。
语法
string.rstrip(characters)
参数值
| 参数 | 描述 |
|---|---|
| characters | 可选。一组作为结尾字符要删除的字符。 |
更多实例
删除结尾字符:
txt = "banana,,,,,ssqqqww....."x = txt.rstrip(",.qsw")print(x)