Python中的rfind()方法使用详解,pythonrfind
Python中的rfind()方法使用详解,pythonrfind
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
相关内容
- Python3.2中Print函数用法实例详解,python3.2print
- 用Python操作字符串之rindex()方法的使用,pythonrindex
- Python中random模块用法实例分析,pythonrandom
- Python递归遍历列表及输出的实现方法,python递归遍输出
- python抓取百度首页的方法,python抓取首页
- Python中的rjust()方法使用详解,pythonrjust
- Python映射拆分操作符用法实例,python操作符
- 在Python中操作字符串之rstrip()方法的使用,pythonrstrip
- python实现提取百度搜索结果的方法,python百度搜索
- Python编程之属性和方法实例详解,python编程实例详解
评论关闭