rfind()方法如果找到子字符串str则返回最后一个索引,或者如果没有这样的索引存在返回-1,可选限制搜索为:string[beg:end].
参数
-
str -- 此选项指定要搜索的字符串
-
beg -- 这是起始索引,默认是0
-
end -- 这是结束索引,默认情况下其等于该字符串的长度
返回值
此方法如果找到则返回最后一个索引,否则返回-1。
#!/usr/bin/python3
str1 = "{this is really a string example....wow!!!"
print(strs[strs.rfind('{'):strs.rfind("!!!")+1].
结果:this is really a string example....wow!!!