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


Picture showing the output of the index function in python



Posted By  -  Karan Gupta
 
Posted On  -  Monday, April 29, 2019

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250