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字串