Python3 string.rstrip()方法

rstrip()方法返回被从字符串(默认空白字符)结束剥离字符串的副本。

语法

以下是 rstrip()可以方法的语法 -
str.rstrip([chars])

参数

  • chars -- 提供必须修剪字符

返回值

这个方法返回所有已经从字符串的结尾(默认空格字符)剥离字符后的字符串副本。

示例

下面的示例显示 rstrip()方法的使用。
#!/usr/bin/python3
str = "     this is string example....wow!!!     "
print (str.rstrip())
str = "*****this is string example....wow!!!*****"
print (str.rstrip('*'))

当我们运行上面的程序,会产生以下结果 -
     this is string example....wow!!!
*****this is string example....wow!!!

上一篇: Python3数字 下一篇: Python3字符串