Find the Index of an Element in a List in Python

  • Post category:List

Finding the index of a specific element in a list is a common task in Python programming. In this blog post, we’ll explore different code examples that demonstrate how to find the index of an element in a list efficiently.

Example 1:

fruits = ['apple', 'banana', 'orange', 'kiwi']
index = fruits.index('orange')
print(index)

Output: 2

Example 2:

numbers = [10, 20, 30, 40, 50]
index = numbers.index(40)
print(index)

Output: 3