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