KnowledgeBoat Logo
|

Robotics & Artificial Intelligence

What should be the output of the following program and why?

my_list=[2,3,4,5,6,7] 
print(my_list[-7]) 

Python List Manipulation

3 Likes

Answer

The program will produce an error.

The list my_list has 6 elements, so valid negative indices range from -1 to -6. The index -7 is out of range, hence Python cannot access any element at that position.

Answered By

3 Likes


Related Questions