這篇文章主要介紹了在Python中操作字符串之rstrip()方法的使用,是Python入門中的基礎(chǔ)知識(shí),需要的朋友可以參考下
rstrip()方法返回所有字符都被去除的字符串(缺省為空格字符)結(jié)束字符串的副本。
語(yǔ)法
以下是rstrip()方法的語(yǔ)法:
- str.rstrip([chars])
參數(shù)
chars -- 可以提供要去除的字符。
返回值
此方法返回的所有字符都被去除的字符串(缺省為空格字符)結(jié)束字符串的副本。
例子
下面的例子顯示了rstrip()方法的使用。
- #!/usr/bin/python
- str = " this is string example....wow!!! ";
- print str.rstrip();
- str = "88888888this is string example....wow!!!8888888";
- print str.rstrip('8');
當(dāng)我們運(yùn)行上面的程序,它會(huì)產(chǎn)生以下結(jié)果:
- this is string example....wow!!!
- 88888888this is string example....wow!!!
新聞熱點(diǎn)
疑難解答
圖片精選