Python字串rstrip()方法

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

上一篇: Python字串 下一篇: Python列表