(May-09-2023, 09:44 PM)Melen Wrote: I can't understand the logic of the "index out of range" error
What specifically is beyond your understanding? If you count all items in object starting from zero and get 0, 1, 2 then what should happen if you are looking for item 4? To put it another way - if you have deck of 5 cards what should you say (or do) if somebody asks to give 6th card in the deck?
Slices can be out of range without raising error:
>>> s = 'abc' >>> len(s) 3 >>> s[3] Traceback (most recent call last): File "<stdin>", line 1, in <module> IndexError: string index out of range >>> s[3:] '' >>> s[100:120] '' >>> l = [1, 2, 3] >>> l[3:] []
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.