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