Python3 find () method
description
find () method to detect whether a string contains a substring str, if you specify beg (start) and end (end) range, it is checked whether contained within the specified range, if it contains the substring returns the index value at the start, otherwise return -1.
grammar
find () method syntax:
str.find(str, beg=0, end=len(string))
parameter
- str - the specified search string
- beg - starting index, the default is 0.
- end - the end of the index, the default is the length of the string.
return value
If you include substring returns the index value at the start, otherwise it returns -1.
Examples
The following example shows an example of find () method:
#!/usr/bin/python3 str1 = "w3big example....wow!!!" str2 = "exam"; print (str1.find(str2)) print (str1.find(str2, 5)) print (str1.find(str2, 10))
Examples of the above output results are as follows:
7 7 -1