Find an Element in a List in Python

  • Post category:List

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

Example 1:

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

Output: 2

Example 2:

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

Output: 3