首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

字符串find步骤的用法

2013-01-19 
字符串find方法的用法今天给大家说下python字符串的find方法,从python的文档里可以知道find方法是查找子串

字符串find方法的用法

今天给大家说下python字符串的find方法,从python的文档里可以知道find方法是查找子串在字符串的开始位置。

看下文档解释:

string.find(s, sub[, start[, end]])
Return the lowest index in s where the substring sub is found such that sub is wholly contained in s[start:end]. Return -1 on failure. Defaults for start and end and interpretation of negative values is the same as for slices

后面的[]是表示可选项,start,end表示查找字符串的开始位置和结束位置。

比如下面的例子:
info = 'abca'
print info.find('a')

返回的结果是:0

info = 'abca'
print info.find('a',1)

返回的结果是:3

info = 'abca'
print info.find('333')
返回的结果是:-1

有兴趣的可以看看python 字符串 index方法。

?

原文:http://www.cnpythoner.com/post/226.html

热点排行