{"id":24772,"date":"2021-11-02T09:46:24","date_gmt":"2021-11-02T04:16:24","guid":{"rendered":"https:\/\/python-programs.com\/?p=24772"},"modified":"2021-11-05T19:16:45","modified_gmt":"2021-11-05T13:46:45","slug":"python-string-index-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-string-index-method-with-examples\/","title":{"rendered":"Python String index() Method with Examples"},"content":{"rendered":"

In the previous article, we have discussed Python String find() Method with Examples<\/a>
\nString index() Method in Python:<\/strong><\/p>\n

The index() method looks for the first instance of the specified value.<\/p>\n

If the value is not found, the index() method throws an exception.<\/p>\n

Note:<\/strong>\u00a0The index() method is nearly identical to the find() method, with the exception that the find() method returns -1 if the value is not found.<\/p>\n

Syntax:<\/strong><\/p>\n

string.index(value, start, end)<\/pre>\n

Parameters<\/strong><\/p>\n

value:<\/strong> This is Required. It is a string. The value to look for in the string.<\/p>\n

start:<\/strong>\u00a0This is optional. It is an integer. The starting point for the search. The default value is 0.<\/p>\n

end:<\/strong>\u00a0This is optional. It is an integer. The ending point for the search. The default value is the end of the string.<\/p>\n

Return Value:<\/strong><\/p>\n