str.rindex(str, beg=0 end=len(string))
str -- 此選項指定要搜尋的字串
beg -- 這是起始索引,預設值是 0
len -- 這是結束索引,預設情況下它等於字串的長度
#!/usr/bin/python3 str1 = "this is really a string example....wow!!!" str2 = "is" print (str1.rindex(str2)) print (str1.rindex(str2,10))
5 Traceback (most recent call last): File "test.py", line 5, in print (str1.rindex(str2,10)) ValueError: substring not found