The find() method returns the lowest index of the substring if it is found in given string. If its is not found then it returns -1.
sub : It’s the substring which needs to be searched in the given string.
start : Starting position where sub is needs to be checked within the string.
end : Ending position where suffix is needs to be checked within the string.
NOTE : If start and end indexes are not provided then by default it takes 0 and length-1 as starting and ending indexes where ending indxes is not included in our search.
returns the lowest index of the substring if it is found in given string. If it’s not found then it returns -1.
The find() method is similar to index(). The only difference is find() returns -1 if searched string is not found and index() throws an exception in this case.
Substring 'geeks' found at index: 0 Substring 'for ' found at index: 6 Doesn't contains given substring
10 -1 -1 6
- String slicing in Python to check if a string can become empty by recursive deletion
- String slicing in Python to rotate a string
- String Alignment in Python f-string
- Pad or fill a string by a variable in Python using f-string
- Find the first repeated word in a string in Python using Dictionary
- Python | Find all close matches of input string from a list
- Python - Find all duplicate characters in string
- Find length of a string in python (4 ways)
- Python | String startswith()
- Python string | strip()
- Python program to split and join a string
- Python String isspace() and its application
- Python String index() and its applications
- Python String isalpha() and its application
- Python code to move spaces to front of string in single traversal
- Python String isdigit() and its application
- Python Regex to extract maximum numeric value from a string
- Concatenated string with uncommon characters in Python
- Python counter and dictionary intersection example (Make a string using deletion and rearrangement)
- Python | Swap commas and dots in a String
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : dubey._.ji