C. · @cazabon
175 followers · 4389 posts · Server mindly.social

@mate

It means the index you supplied is past the end of the list, or before the beginning. List indices start at 0, which sometimes trips people up.

>>> l = [1, 2, 3]
>>> l[2]
3
>>> l[-3]
1
>>> l[3]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> l[-4]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range

Happy to look at code if you post it.

#0based #list #python

Last updated 1 year ago

screw_dog · @screw_dog
198 followers · 1603 posts · Server aus.social

One point I've never seen mentioned in the Array Indexing Wars is that source code is always numbered from 1.

Like, even the C standard mandates that the first line of code in a file is numbered 1

#programming #arrayindexing #0based #1based #c

Last updated 1 year ago