What is the correct fix?
nums = [1, 2, 3] print(nums.index(9))
- Check first:
if 9 in nums:before index - Check first:
if nums.has(9):before index - Change
index(9)tonums.find(9)here - Wrap the print call in a
str()cast
list.index raises ValueError when the value is absent — unlike JS indexOf, it never returns -1.
Play Problem Solving ▸