What is the output of the following Python code snippet?
try:
'python'.index('z')
except Exception as e:
print(type(e).__name__)
-
A
-1
-
B
ValueError
Correct answer
-
C
None
-
D
0
Correct answer
B. ValueError
Explanation
index() raises ValueError when the substring is missing.
Doubts & discussion
Not sure why the answer is B? Ask here and get an explanation.
Ask a doubt about this MCQ