How to handle no element found in List index() Method with Python

1 Answer

0 votes
lst = [12, 33, 51, 77, 90, 100, 171]
 
# print(lst.index(600)) # ValueError: 600 is not in list
 
try :
    print(lst.index(600))
except ValueError:
    print('Not found')
 
 
'''
run:
 
Not found
 
'''
 

 



answered Jan 25 by avibootz
...