I have a list and want to print it’s elements like (print myList[5]) but i am facing this error:
IndexError: list index out of range
please someone guide me why this error is raising
Sign Up to our social questions and Answers to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers to ask questions, answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Hi,
this happens because you have specified wrong index number here is the example of how this error are raised:
alphabet=[‘a’,’b’,’c’];print(alphabet[3])
IndexError: list index out of range
in above example we want to to print the last element in the list which is (‘c’), but we have passed the wrong index number because the correct one is print(alphabet[2]).
that’s because list index starts with 0 not with 1
This example have been taken from this article here
you can refer to it for better understanding.
I hope this will help you.