Skip to content

Latest commit

 

History

History
34 lines (19 loc) · 415 Bytes

File metadata and controls

34 lines (19 loc) · 415 Bytes

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