内容简介:Python rindex() 返回子字符串 str 在字符串中最后出现的位置,如果没有匹配的字符串会报异常,你可以指定可选参数[beg:end]设置查找的区间。
描述
Python rindex() 返回子字符串 str 在字符串中最后出现的位置,如果没有匹配的字符串会报异常,你可以指定可选参数[beg:end]设置查找的区间。
语法
rindex()方法语法:
str.rindex(str, beg=0 end=len(string))
参数
- str -- 查找的字符串
- beg -- 开始查找的位置,默认为0
- end -- 结束查找位置,默认为字符串的长度。
返回值
返回子字符串 str 在字符串中最后出现的位置,如果没有匹配的字符串会报异常。
实例
以下实例展示了rindex()函数的使用方法:
#!/usr/bin/python str1 = "this is string example....wow!!!"; str2 = "is"; print str1.rindex(str2); print str1.index(str2);
以上实例输出结果如下:
5 2
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 理解实例方法、类方法、静态方法
- 【MyBatis源码分析】insert方法、update方法、delete方法处理流程(上篇)
- 【MyBatis源码分析】insert方法、update方法、delete方法处理流程(上篇)
- java:方法覆盖与方法重载
- 静态方法、实例化方法与线程安全
- JS数组方法总览及遍历方法耗时统计
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Big Java Late Objects
Horstmann, Cay S. / 2012-2 / 896.00元
The introductory programming course is difficult. Many students fail to succeed or have trouble in the course because they don't understand the material and do not practice programming sufficiently. ......一起来看看 《Big Java Late Objects》 这本书的介绍吧!