1、rindex函数次要用于在给定的字符串中找到子字符串是否存在。如果找到,返回子串的第一个索引地位,否则会间接抛出异样。
2、rindex开始从字符串的右侧搜寻,但返回的索引依然从左侧计算。
实例
mystr = 'hello world and hello python' #1.在整个字符串中查找print(mystr.rindex('python')) #输入后果22 #2.在字符串的指定地位内查找print(mystr.rindex('python',0,20)) #返回后果报异样:ValueError:substring not found
以上就是python中rindex函数的介绍,心愿对大家有所帮忙。