Skip to content

Latest commit

 

History

History
39 lines (25 loc) · 489 Bytes

File metadata and controls

39 lines (25 loc) · 489 Bytes

IndexError: string index out of range

Occurs when accessing a character outside the string length.

Reproduce

text = "hi"

print(text)
char = text[5]
print(char)

Error Message

IndexError: string index out of range

Fix

text = "hi"

print(text)
if len(text) > 5:
    char = text[5]
    print(char)

Reflection

Ended up accessing an index that didn’t exist.

Reference