How to use the string find() method?
String.find() method returns the index of a substring in a string and using the find() function is very easy. You just need to call the find function with the object string and pass the substring as a parameter.
Let’s understand it better with an example:
Python3
string = " hello world is the first code of every programmer" print (string.find( "first" )) |
Output
20
Python String find() method
Python String find() method returns the lowest index or first occurrence of the substring if it is found in a given string.
Example
Python3
# initializing a string word = 'find me if you can' # using string find() method print (word.find( 'me' )) |
Output
5