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



Click to Enlarge


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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250