Python String index() Method
Returns the index of the first matching substring within the given string. If the index is not found, Python throws a
string.index(value, start = None, end = None)
||Required. The value to search for.|
||Optional. The index at which to start searching. The default is None meaning 0.|
||Optional. The index at which to stop searching. The default is None meaning the end of the string.|
str = 'The quick brown fox jumped over the lazy dog' print(str.index('brown')) try: print(str.index('horse')) except ValueError: print('The string "horse" was not found!')
10 The string "horse" was not found!