get index of item in array in python

To get the index of an item in an array in Python, you can use the index method on the array with the item as an argument. Here's an example:

main.py
my_array = ["apple", "banana", "orange"]
index_of_banana = my_array.index("banana")
print(index_of_banana)
107 chars
4 lines

In this example, the index method is used to get the index of the string "banana" in the my_array list. The index number is then printed to the console, which will output 1, since "banana" is the second item in the array (with an index of 1, since array indexes start at 0 in Python).

related categories

gistlibby LogSnag