Web/python
[python](error) is not in list
oSsonGo
2022. 3. 12. 18:34
배열 값 중 index를 알아오기 위해 index 함수 사용 시
ValueError: 값 is not in list 에러 발생
해당 에러는 리스트 안에 '값이 없을 때 발생
- 하기 코드 실행 시 'ValueError: 5 is not in list' 에러 발생
arrVal = [1, 2, 3, 4]
print(arrVal.index(5)
- 예외처리
try :
idx = arr.index(val)
except ValueError :
print("ValueError")