繁体   English   中英

Python.find() 字符串方法返回什么?

[英]What does the Python .find() string method return?

我想知道是否可以从您那里获得有关 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.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.

google 文档字符串中你不理解的所有单词,你就会有答案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM