Latest web development tutorials

Python rstrip()方法

Python 字符串 Python字符串


描述

Python rstrip() 刪除string 字符串末尾的指定字符(默認為空格).

語法

rstrip()方法語法:

str.rstrip([chars])

參數

  • chars -- 指定刪除的字符(默認為空格)

返回值

返回刪除string 字符串末尾的指定字符後生成的新字符串。

實例

以下實例展示了rstrip()函數的使用方法:

#!/usr/bin/python

str = "     this is string example....wow!!!     ";
print str.rstrip();
str = "88888888this is string example....wow!!!8888888";
print str.rstrip('8');

以上實例輸出結果如下:

     this is string example....wow!!!
88888888this is string example....wow!!!

Python 字符串 Python字符串