Source Code:
(back to article)
# Define the list my_list = [1, 2, 3, 4, 5] # Define the element to search for search_element = 3 try: index = my_list.index(search_element) print(f"{search_element} is at index {index} in the list.") except ValueError: print(f"{search_element} is not in the list.")
Result:
Report an issue