What will be the output of the following Python code? [code]lst = [1, 2, 3] lst[3][/code]

What will be the output of the following Python code?
Code:
lst = [1, 2, 3]
lst[3]
A. NameError
B. ValueError
C. IndexError
D. TypeError
 
Answer: c
Explanation: The snippet of code shown above throws an index error. This is because the index of the list given in the code, that is, 3 is out of range. The maximum index of this list is 2.
 

Tìm kiếm

Back
Top