Source Code:
(back to article)
my_list = [1, 2, 3, 4, 5] # Find the index of 3 in the list index = my_list.index(3) print(index) # Output: 2 # Find the index of 6 in the list try: index = my_list.index(6) except ValueError: print("6 is not in the list") # Output: # 2 # 6 is not in the list
Result:
Report an issue