手机
当前位置:查字典教程网 >脚本专栏 >python >在Python中操作字符串之rstrip()方法的使用
在Python中操作字符串之rstrip()方法的使用
摘要:rstrip()方法返回所有字符都被去除的字符串(缺省为空格字符)结束字符串的副本。语法以下是rstrip()方法的语法:str.rstri...

rstrip()方法返回所有字符都被去除的字符串(缺省为空格字符)结束字符串的副本。

语法

以下是rstrip()方法的语法:

str.rstrip([chars])

参数

chars -- 可以提供要去除的字符。

返回值

此方法返回的所有字符都被去除的字符串(缺省为空格字符)结束字符串的副本。

例子

下面的例子显示了rstrip()方法的使用。

#!/usr/bin/python str = " this is string example....wow!!! "; print str.rstrip(); str = "88888888this is string example....wow!!!8888888"; print str.rstrip('8');

当我们运行上面的程序,它会产生以下结果:

this is string example....wow!!! 88888888this is string example....wow!!!

【在Python中操作字符串之rstrip()方法的使用】相关文章:

Python中针对函数处理的特殊方法

Python中使用动态变量名的方法

python 字符串split的用法分享

Python内置的字符串处理函数整理

Python 连接字符串(join %)

在python中的socket模块使用代理实例

Python中字典(dict)和列表(list)的排序方法实例

python三元运算符实现方法

Python 字符串中的字符倒转

python中的yield使用方法

精品推荐
分类导航