Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

readme.md

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