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