Here are eight ways to check if an element is in the list in Python:
- Using in operator
- Using enumerate() and for loop
- Using list comprehension to get indices
- Using index()
- Using count()
- Using any()
- Using filter()
- Using for loop

Method 1: Using in operator

Here is an example of how to use the “in” operator.
main_list = [11, 21, 19, 46]
if 19 in main_list:
print("Element is in the list")
else:
print("Element is not in the list")
Output
Element is in the list
Method 2: Using enumerate() with for loop
The enumerate() function is often used alongside a for loop to iterate over a sequence while keeping track of the index of the current item. This is particularly helpful when you need to find the index of an element in a list.

Here’s how you can use enumerate() within a for loop to find the index of an element in a list:
main_list = [11, 21, 19, 46]
search_element = 19
found_element = False
for index, item in enumerate(main_list):
if item == search_element:
found_element = True
print(f"{search_element} found_element at index {index}")
break
if not found_element:
print(f"{search_element} not found_element in the list")
Output
19 found_element at index 2
Method 3: Using list comprehension
If you are looking for all indices of a certain element in a list, list comprehension is quite handy.

Here’s an example of how you might use it:
main_list = [11, 21, 19, 46]
search_element = 19
indices = [index for index, item in enumerate(
main_list) if item == search_element]
if indices:
print(f"{search_element} found at indices {indices}")
else:
print(f"{search_element} not found in the list")
Output
19 found at indices [2]
Method 4: Using index()
The list.index() method searches for an element in the list and returns its index.
If the same element is present more than once, the method returns the index of the first occurrence of the element. The index in Python starts from 0, not 1. So, through an index, we can find the position of an element in the list.

Here is a small and simple code example of using the list.index() method.
main_list = [11, 21, 19, 46]
search_element = 19
index = main_list.index(search_element)
print(index)
Output
2
Method 5: Using count()
The list.count() method returns the number of times the given element in the list.
Syntax
list.count(element)
It takes a single argument element, the item that will be counted.

Here is a code example to demonstrate the count() method.
main_list = [11, 21, 19, 46]
count = main_list.count(21)
if count > 0:
print("Element is in the list")
else:
print("Element is not in the list")
Output
Element is in the list
Method 6: Using list comprehension with any()
The any() function returns True if any element in an iterable is True. Otherwise, it returns False.

Here is how to use any() function.
main_list = [11, 21, 19, 46]
output = any(item in main_list for item in main_list if item == 22)
print(str(bool(output)))
Output
False
Method 7: Using filter()
The filter() method iterates through the list’s elements, applying the function to each. It returns an iterator that iterates through the elements when the function returns True.

Here is a code example.
main_list = [11, 21, 19, 46]
filtered = filter(lambda element: element == 19, main_list)
print(list(filtered))
Output
[19]
Method 8: Using for loop
main_list = [11, 21, 19, 46]
for i in main_list:
if(i == 46):
print("Element Exists")
Output
Element Exists
Which method to use and why?
I ran a research and experiment to find out which method is fast and efficient for finding an element in the list, and my conclusion is that most of the methods take 0 seconds or no time. That means most of the methods are performant, but when it comes to clear code, “in operator” stands out from the other approaches.
Here is the result of the experiment.
I used the time module to measure the execution time of different approaches or code blocks like this.
For more information about the experiment code, you can check the code I put on Github.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.