#0based

Dmitri Goosens :elephpant:dgoosens@phpc.social
2023-11-07

hahaha

#0based

@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

2023-07-18

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

Client Info

Server: https://mastodon.social
Version: 2025.04
Repository: https://github.com/cyevgeniy/lmst