OiO.lk Blog python list index out of range with a while loop explanation
python

list index out of range with a while loop explanation


A = [1,2,3,4,5]
i = 0
while i < len(A) :
    i += 1
    print(A[i])

and the output gave me
2
3
4
5
which is understandable but I don’t see how my index is out of range , someone please help me

I only expect the result without the "1" but I don’t know why it also has index error out of range , I know I can fix this by replace the order of my 4th and 5th line but I’m curious why my original answer have such error



You need to sign in to view this answers

Exit mobile version