Python find () method
description
Python 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/python str1 = "this is string example....wow!!!"; str2 = "exam"; print str1.find(str2); print str1.find(str2, 10); print str1.find(str2, 40);
Examples of the above output results are as follows:
15 15 -1