手机
当前位置:查字典教程网 >脚本专栏 >python >Python中的rfind()方法使用详解
Python中的rfind()方法使用详解
摘要:rfind()方法返回所在子str被找到的最后一个索引,或者-1,如果没有这样的索引不存在,可选择限制搜索字符串string[beg:end...

rfind()方法返回所在子str 被找到的最后一个索引,或者-1,如果没有这样的索引不存在,可选择限制搜索字符串string[beg:end].

语法

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

str.rfind(str, beg=0 end=len(string))

参数

str -- 此选项指定要搜索的字符串 beg -- 这是开始索引,默认情况下为 0 end -- 这是结束索引,默认情况下它等于该字符串的长度

返回值

此方法如果找到返回最后一个索引,否则返回-1

例子

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

#!/usr/bin/python str = "this is really a string example....wow!!!"; str = "is"; print str.rfind(str); print str.rfind(str, 0, 10); print str.rfind(str, 10, 0); print str.find(str); print str.find(str, 0, 10); print str.find(str, 10, 0);

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

5 5 -1 2 2 -1

【Python中的rfind()方法使用详解】相关文章:

python调用shell的方法

python 切片和range()用法说明

python中文乱码的解决方法

python中的sort方法使用详解

python使用mysqldb连接数据库操作方法示例详解

python之import机制详解

python中stdout输出不缓存的设置方法

vc6编写python扩展的方法分享

Python中使用urllib2防止302跳转的代码例子

python迭代器的使用方法实例

精品推荐
分类导航