x[i] and slices x[a..b] work on lists, strings and maps (m[k]). This value is none of
those.
Wrong#
fn digit(n: int): int = n[0]Fixed#
fn digit(n: int): int = int(str(n)[0]) - int('0')Common causes#
- Indexing a number: convert it with
str(n)first. - Indexing a tuple: use
t.0,t.1. - Indexing a struct: use its field names.
- Indexing a
T?: unwrap it first.