[Python] "IndexError: list index out of range" when accessing 5th element of array of 3 items...

Discussão em 'Python' iniciado por Stack, Novembro 28, 2025.

  1. Stack

    Stack Membro Participativo

    Error I am getting:

    IndexError: list index out of range


    My code:

    number = [1, 2, 3]
    print(number[5])


    I expected it to print the element at index 5.

    I tried:


    • Checking my list.


    • Printing other indexes.

    I still couldn't understand why this error happens. Why is this error happening, and how can I fix it?

    Continue reading...

Compartilhe esta Página