功能:
Python3 rindex()方法将会返回在指定的区间内源字符串中子字符串最后出现的位置。
语法:
str.rindex(zstr, start=0 end=len(string))参数说明:
str:源字符串
zstr:需要查找的子字符串
start:可选参数,默认值为0,指定开始查找的位置
end:可选参数,默认为源字符串长度,指定结束查找的位置
返回值:
如果在源字符串中找到了子字符串,则返回子字符串最后出现的位置,否则将会抛出异常。
注意事项:
1、其余字符串方法见:http://www.mihuguan.com/article/15703730746.html
实例说明:
>>>str1 = "hello python" >>>str2 = "lo" >>>print (str1.rindex(str2)) >>>print (str1.rindex(str2,6)) 3 Traceback (most recent call last): File "test.py", line 6, inprint (str1.rindex(str2,10)) ValueError: substring not found
电脑2020-03-29
HTML2020-03-25
HTML2020-01-26
python2019-11-21
HTML2020-02-13
HTML2019-12-20