Python.find()字符串方法返回什么?
我想知道能否从您那里得到一些关于python中.find()字符串方法的帮助。下面是一个例子:Python.find()字符串方法返回什么?,python,Python,我想知道能否从您那里得到一些关于python中.find()字符串方法的帮助。下面是一个例子: word = 'banana' index = word.find('a') 1#result word.find('na') 2#result word.find('na', 3) 4#result name = 'bob' name.find('b', 1, 2) -1#result 你能解释一下这个字符串方
word = 'banana'
index = word.find('a')
1#result
word.find('na')
2#result
word.find('na', 3)
4#result
name = 'bob'
name.find('b', 1, 2)
-1#result
你能解释一下这个字符串方法具体做什么吗?
同样对于word.find('na')和word.find('b',1,2')这两部分,运行这些命令时的数字是什么,结果的含义是什么??谢谢你的帮助
In [1]: print str.find.__doc__
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.
用谷歌搜索你不懂的文档字符串中的所有单词,你就会得到答案数字是索引。因此,在上一个示例中,它在
'bob'[1:2]
中搜索'b',但没有找到它(因为'bob'[1:2]
是'o'):