Python 字符串方法
删除字符串右边的空格:
txt = " banana " x = txt.rstrip() print("of all fruits", x, "is my favorite")
运行实例
rstrip() 方法删除所有结尾字符(字符串末尾的字符),空格是要删除的默认结尾字符。
string.rstrip(characters)
删除结尾字符:
txt = "banana,,,,,ssaaww....." x = txt.rstrip(",.asw") print(x)