rstrip()方法


rstrip()方法

描述

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

語法

rstrip()方法語法:

str.rstrip([chars])

參數

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

返回值

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

實例

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

str = "     this is string example....wow!!!     "
print(str.rstrip())  #     this is string example....wow!!!

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

 


免責聲明!

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



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