Let’s check how to get index of item in list using Python.
We have a list and string defined. To check and index it is enough to use index function with string as a parameter.
my_list = ['this', 'is', 'my', 'playground'] string = 'playground' index = my_list.index(string) print(f"Index of item is {index}")
Function returns an index number of given string which we printed out.
Remember that computers are counting from 0. In fact index 3 means that this is the 4th element in the list.