Articles → Python → Index Function In Python
Index Function In Python
Purpose
Syntax
string_variable.index(word_to_search)
Or
list.index(word_to_search)
Example
# Finding word in a string using index method.
message = "Hello, How are you"
print("Index of word 'How' in the string is:", message.index("How"))
# Finding word in a list using index method.
mylist = ["Apple","Orange", "Banana"]
print("Index of word 'Banana' in the list is:", mylist.index("Banana"))
Output