首页 > 编程语言 > 详细

Python 的字符串类子串查找函数

时间:2017-03-20 22:21:28      阅读:231      评论:0      收藏:0      [点我收藏+]

Python 的字符串类有个很好用的函数,可很方便的用于与查找Python字符串类型对象子串相关的操作,具体的API如下:

|  find(...)
|     S.find(sub [,start [,end]]) -> int
|     
|     Return the lowest index in S where substring sub is found,
|     such that sub is contained within s[start:end]. Optional
|     arguments start and end are interpreted as in slice notation.
|     
|     Return -1 on failure

假定S为string类型的对象,调用find函数,将子串或子串的子串(也就是子串从start到end的切片)作为参数传入。

返回值为int类型,若S包含有传入参数sub,则返回子串(substring)在父串(S)中的索引,若不包含作为参数传入的子串,则返回-1代表查找索引失败。

Python 的字符串类子串查找函数

原文:http://www.cnblogs.com/maoguy/p/6591729.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!