0
The error message cut of the script
If the script is the following: letters = ['p', 'q', 'r', 's', 'p', 'u'] print(letters.index('r')) print(letters.index('n')) print(letters.index('s')) The output is 2 Traceback (most recent call last): File "./Playground/file0.py", line 3, in <module> print(letters.index('n')) ValueError: 'n' is not in list But.. there is no answer for the third line. Why? Does the error command imply that the next line is not executed?
5 Antworten
+ 1
something like:
letters = ['p', 'q', 'r', 's', 'p', 'u']
print(letters.index('r'))
try:
print(letters.index('n'))
except ValueError:
print("does not exist")
print(letters.index('s'))
+ 2
since n does not exist it throws an exception. if you want to continue to the third print.
handle the ValueError exception.
+ 2
There is an answer for the 3rd line, it does tell you that ValueError: 'n' is not in list. When the python parser found an error, it stops the rest of the script's execution, so you must catch the error, with a try catch block.
+ 1
If the error isn't handled the script won't continue executing