13 lines
416 B
Python
13 lines
416 B
Python
# Write a Python program that executes an operation on a list and handles an IndexError exception if the index is out
|
|
# of range.
|
|
|
|
# Defines 'test_list' var with 4 elements, indices 0-3.
|
|
test_list = ['a', 'b', 'c', 'd']
|
|
# Try printing the 4th index in the list
|
|
try:
|
|
print(test_list[4])
|
|
# Handle the expected IndexError
|
|
except IndexError:
|
|
# Print an error message
|
|
print('That list entry does not exist.')
|