第三章 7-4 查找指定字符

s=input()
strl=input()
if s in strl:
    print('index = {}'.format(strl.rindex(s)))
else:
    print('Not Found')

rindex()方法语法

str.rindex(str, beg=0 end=len(string))

参数:
-str -- 查找的字符串
-beg -- 开始查找的位置,默认为0
-end -- 结束查找位置,默认为字符串的长度。

返回值:
返回子字符串 str 在字符串中最后出现的位置,如果没有匹配的字符串会报异常
发布了80 篇原创文章 · 获赞 6 · 访问量 7637

猜你喜欢

转载自blog.csdn.net/qq_33749437/article/details/104881375