The “IndexError” happens when you run out of your array length. This error happens with the following code:
>>> test_tuple = (1, "Hello", True)
>>> test_tuple # 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.