Product SiteDocumentation Site

8.3. Finding text

Stings have some methods which will help you in finding text/substring in a string. Examples are given below:
>>> s.find("for")
7
>>> s.find("fora")
-1
>>> s.startswith("fa") #To check if the string startswith fa or not
True
>>> s.endswith("reason") #
True

find() helps to find the first occurrence of the substring given, if not found it returns -1.