• Register
1 vote


indexerror: tuple index out of range what does it mean? Why I am getting this error?
Please shed some light on this if possible.


15.3k points
reopened by

Please log in or register to answer this question.

1 Answer

2 votes
Best answer


The “IndexError” happens when you run out of your array length. This error happens with the following code:

>>> test_tuple = (1, "Hello", True)
>>> len(test_tuple)
>>> test_tuple[0]
>>> test_tuple[3]  # Trying to access the 4th element
IndexError: tuple index out of range

Now coming to the second part of your question. Please focus on this simple python program. I got the error when I tried to access the element I don’t have ever. This is similar to trying to access the 10th element of a list of length 9.
I hope you get the point. Thanks.



    94.3k points
    selected by