Python/ref string rstrip
来自菜鸟教程
<languages />
Python字符串rstrip()方法
例
删除字符串末尾的所有空格:
txt = " banana "
x =
txt.rstrip()
print("of all fruits", x, "is my favorite")
定义和用法
The
rstrip()
方法删除所有结尾字符(字符串末尾的字符),空格是要删除的默认结尾字符。
句法
string.rstrip(characters)
参数值
| 参数 | 描述 |
|---|---|
| characters | 可选的。一组要删除的字符作为结尾字符 |
更多例子
例
如果结尾的字符是逗号,s,q或w,请删除它们:
txt = "banana,,,,,ssqqqww....."
x = txt.rstrip(",.qsw")
print(x)