• 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.


12 7 7
15,250 points

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.



    13 9 6
    94,240 points

    Related questions

    0 votes
    1 answer 31 views
    I wrote a code in python : l = [8, 5, 4] total = l[0] + l[1] print (total) def count(a): total = 0 for i in a: total+= a[i] return total print (count(n)) but it has some error: File "main.py", line 11 return total ^ SyntaxError: 'return' outside function What is this error causing for?
    asked Mar 15, 2020 LizzyM 6.1k points
    0 votes
    1 answer 4 views
    Problem: Please consider the following code: i = [1, 2, 3, 5, 8, 13] j = [] k = 0 for l in i: j[k] = l k += 1 print j The output (Python 2.6.6 on Win 7 32-bit) is: > Traceback (most recent call last): > j[k] = l IndexError: list assignment index out of range I guess it's something simple I don't understand. Can someone clear it up?
    asked 5 days ago Mashhoodch 5.6k points
    1 vote
    1 answer 19 views
    Problem: I am new in python programming and I have been following a course where I have been instructed to do an assginement to remove all occurrences of a character in a list python. So I write this code: Numbs = [11, 22, 11, 33, 11, 44, 11, 55] a = 11 print (" ... main.py", line 8, in <module> if(Numbs[i]==a): IndexError: list index out of range Can anyone help me out to solve this problem?
    asked Apr 6, 2020 LizzyM 6.1k points
    1 vote
    2 answers 95 views
    Problem: I am trying to adopt the python programming language. Learning it step by step and practicing daily. I&rsquo;ve written simple code that contains a list and run an iteration on it but it shows: python indexerror: list assignment index out of range m = [1, 2, 3, 5, 8, 13] n = [] o = 0 for l in m: n[o] = l o += 1 print n Where did I wrong? Any Idea?
    asked Mar 30, 2020 Gavin 15.3k points
    1 vote
    1 answer 26 views
    Problem: I was discovering String in python. Suddenly I stuck here by getting &ldquo;indexerror: string index out of range&rdquo; this error message. def print_letters(string): count = 0 newstring = [] while count <= len(string): m = string[count] count +=1 print m print_letters("blanks") Do you have any idea? I&rsquo;d appreciate it if you figure the error in my program.
    asked Mar 7, 2020 Gavin 15.3k points
    1 vote
    1 answer 190 views
    Problem: I have been doing programming for a while and I am using python for this. So my question is What is an advantage of using a tuple rather than a list? Thank you
    asked Apr 6, 2020 LizzyM 6.1k points
    0 votes
    1 answer 6 views
    How can I solve this?
    asked Dec 30, 2020 TeamScript 9.2k points
    0 votes
    1 answer 416 views
    Problem : I was playing and below error just popped up and it just did not close. Array index is out of range. [system.indexoutofrangeexception] details: no details I tried to restart the game and when I tried to boot the save it shows the error message again and when ... and the river is completely grey. I have been playing the game for more than 20 hrs. Still I hope the issue can be fixed.
    asked Dec 18, 2019 alecxe 7.5k points
    0 votes
    1 answer 41 views
    Problem : I want to add the data as one by one row to my datagridview. But I am facing the following error: "Index was out of range. Must be non-negative and less than the size of the collection parameter name: index" Why am I facing this error ? ... ColumFive = Convert.ToString(sum); string[] row = new string[]{ ColumOne, ColumTwo, ColumThree, ColumFour, ColumFive }; myDataGridView.Rows.Add(row);
    asked Dec 4, 2019 alecxe 7.5k points