Skip to main content

Posts

Showing posts with the label find method

python3 string find method

Description It determines if string str occurs in string, or in a substring of string if starting index beg and ending index end are given. Syntax str.find(str, beg=0, end=len(string)) Parameters str − This specifies the string to be searched. beg − This is the starting index, by default its 0. end − This is the ending index, by default its equal to the length of the string. Return Value Index if found and -1 otherwise. Example: Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> str1 = "This is a string to test the find method." >>> str2 = "string" >>> print(str1.find(str2)) 10 >>> print(str1.find(str2,10)) 10 >>> print(str1.find(str2,10+1)) -1 >>>