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!!!