To check if a specific element is present in a list in Python, you can use the in
operator.
In this example,
my_list
with some elements.in
operator to check if the specified element is present in the list.in
operator returns True
if the element is present, otherwise False
.my_list = [10, 20, 30, 40, 50]
search_element = 40
is_present = search_element in my_list
print('Element presence in list:', is_present)
Element presence in list: True
In this example,
my_list
with some string elements.in
operator to check if the specified string is present in the list.in
operator returns True
if the string is present, otherwise False
.my_list = ['apple', 'banana', 'cherry', 'date', 'elderberry']
search_element = 'cherry'
is_present = search_element in my_list
print('Element presence in list:', is_present)
Element presence in list: True
In this tutorial, we learned How to check if a Specific Element is present in the List in Python language with well detailed examples.