Python rstrip() 方法


描述

Python rstrip() 方法用於刪除字符串尾部指定的字符,默認字符為所有空字符,包括空格、換行(\n)、制表符(\t)等。

語法

rstrip() 方法語法:

S.rstrip([chars])

參數

  • chars -- 可選參數,要刪除的指定字符,默認字符為所有空字符,包括空格、換行(\n)、制表符(\t)等。

返回值

返回刪除字符串尾部指定的字符后生成的新的字符串。

實例

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

#!/usr/bin/python3

S = "     this is string example....wow!!!     "
print (S.rstrip())
S = "*****this is string example....wow!!!*****"
print (S.rstrip('*'))

以上實例輸出結果如下:

     this is string example....wow!!!
*****this is string example....wow!!!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM