Python String index() Method

Python String index() Method

  • The index() method finds the first occurrence of the specified value.

  • The index() method raises an exception if the value is not found.

  • The index() method is almost the same as the find() method, the only difference is that the  find() method returns -1 if the value is not found.

Syntax

string.index(value, start, end)

Parameter

value

                 Required. The value to search for

start

                 Optional. Where to start the search. Default is 0

end

                 Optional. Where to end the search. Default is to the end of the string

 

 

 

 

Comments