The following list is given: numbers = [1, 4, 5, 7] What value will be returned when we want to read the item with index 4? numbers[4]

Questions & AnswersCategory: PythonThe following list is given: numbers = [1, 4, 5, 7] What value will be returned when we want to read the item with index 4? numbers[4]
Lokesh Kumar Staff asked 2 years ago

The following list is given:

numbers = [1, 4, 5, 7]

What value will be returned when we want to read the item with index 4?

numbers[4]

a. The NameError will be raised.
b. 7
c. The IndexError will be raised.
d. The keyError will be raised.
e. None

1 Answers
Lokesh Kumar Staff answered 2 years ago

c. The IndexError will be raised.
 
Explanation:
IndexError is raised when a sequence subscript is out of range. (Slice indices are silently truncated to fall in the allowed range; if an index is not an integer, TypeError is raised.)