Python String find()

Posted LilyLiya

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python String find()相关的知识,希望对你有一定的参考价值。

The find() method returns the lowest index of the substring if it is found in given string. If its is not found then it returns -1.

Syntax :

str.find(sub,start,end)

Parameters :

sub : It’s the substring which needs to be searched in the given string.
start : Starting position where sub is needs to be checked within the string.
end : Ending position where suffix is needs to be checked within the string.

NOTE : If start and end indexes are not provided then by default it takes 0 and length-1 as starting and ending indexes where ending indxes is not included in our search.

Returns:

returns the lowest index of the substring if it is found in given string. If it’s not found then it returns -1.

The find() method is similar to index(). The only difference is find() returns -1 if searched string is not found and index() throws an exception in this case.

以上是关于Python String find()的主要内容,如果未能解决你的问题,请参考以下文章

Python 调整日期格式

python 简单的Pytho WebSocket

Python find()方法

find() python

Python如何将RGB图像转换为Pytho灰度图像?

python基础总结(字符串)