Python String Find Tutorial with Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/python-string-find-tutorial-examples/
PINTEREST
PINTEREST
INSTAGRAM

Python provides a lot of string functions and functionalities. But finding string in a string or text is popular use case in the application developers. In this tutorial we will look different usage of find function of string type.

Just Find

We will use find function and provide the string we are searching for. As we know find function is provided by string types where we will search in. In this example we will search pof in the string variable named mytext .

As we can see that the start index is the string is returned. If the given string is not founded in the text mytext it will be -1 returned.

Find From Given Index

While searching given string in a text it may not convenient start searching from begging of the text. find function provides the ability to specify where to start. We will provide the start index of the search operation and search to the end of the text.

In this example we will start from index 10 which is tenth character of the text.

Find From Given Index

Find From Given Index

Set Search End Index

Another search limiting feature is setting the end of the search index. So the find function will search up to given index. In this example we should provide both start and end index. If we want to start searching from begging we can set it as  . We will search up to 10 .

LEARN MORE  Python String Variable Type

Set Search End Index

Set Search End Index

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/python-string-find-tutorial-examples/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)