Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

readme.md

TypeError: string indices must be integers

Reproduce

text = "hello"

idx = "1"
print(text[idx])

Error message

TypeError: string indices must be integers, not 'str'

Fix

text = "hello"

idx = int("1")
print(text[idx])

Reflection

I passed a string variable as an index without realizing it.

Reference