码迷,mamicode.com
首页 > 编程语言 > 详细

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

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

标签:style   start   ota   方便   ice   类型   pytho   操作   失败   

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 的字符串类子串查找函数

标签:style   start   ota   方便   ice   类型   pytho   操作   失败   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!