手机
当前位置:查字典教程网 >脚本专栏 >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多线程编程方式分析示例详解

Python中apply函数的用法实例教程

python中文乱码的解决方法

python函数返回多个值的示例方法

python中的sort方法使用详解

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

Python中__init__和__new__的区别详解

Python 的 with 语句详解

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

Python中文件遍历的两种方法

精品推荐
分类导航