
rfind()方法返回字符串最后一次出现的位置(从右向左查询),如果没有匹配项则返回-1。
rfind()的语法为:
str.rfind(sub[, start[, end]] )
rfind()参数
rfind()方法最多使用三个参数:
- sub- 它是在str字符串中要搜索的子字符串。 
- start和end (可选)-在str[start:end]其中搜索子字符串 
rfind()返回值
rfind()方法返回一个整数值。
- 如果子字符串存在于字符串中,则它返回找到子字符串的最大索引。 
- 如果字符串中不存在子字符串,则返回-1。 

示例1:没有开始和结束参数的rfind()
quote = 'Let it be, let it be, let it be'
result = quote.rfind('let it')
print("子字符串 'let it':", result)
result = quote.rfind('small')
print("子字符串 'small ':", result)
result = quote.rfind('be,')
if  (result != -1):
  print("be 出现的地方最大的索引值:", result)
else:
  print("不包含子字符串")运行该程序时,输出为:
子字符串 'let it': 22 子字符串 'small ': -1 be 出现的地方是最的索引值: 18
示例2:带有开始和结束参数的rfind()
quote = 'Do small things with great love'
#搜索子字符串 'hings with great love'
print(quote.rfind('things', 10))
# 搜索子字符串 ' small things with great love' 
print(quote.rfind('t', 2))
# 搜索子字符串 'hings with great lov'
print(quote.rfind('o small ', 10, -1))
# 搜索子字符串 'll things with'
print(quote.rfind('th', 6, 20))运行该程序时,输出为:
-1 25 -1 18
