I'm sorry for the very basic question, this is a concept I can't quite grasp.
It is my understanding that the first element in a Python list has index [0]
. This means that len(x)-1
should be the last element in my list x.
So, if I write a loop with:
for i in range(0, len(x)-1):
#do stuff here
This should mean that I want I to go from the first element of my list to the last one.
However, I always find written:
for i in range(0, len(x)):
#do stuff here
Why is that? Which one is correct?