본문 바로가기
Coding/Python

[Python] 파이썬 TypeError: string indices must be integers 에러 원인 및 해결 방법 !!

by 포스트it 2022. 7. 27.
반응형

 

[Python] 파이썬 TypeError: string indices must be integers 에러 원인 및 해결 방법 !!

 

TypeError: string indices must be integers 에러의 원인은

인덱스 값이 정수가 아닌 경우 일때 발생하는 에러입니다.

 

EX)

>>> a = 1
>>> hello[a]
'h'


>>> hello[a+1]
'e'


>>> hello[1.5]
TypeError: string indices must be integers

 

결론은 인덱스값을 정수로 바꾸면 에러가 해결 됩니다 :)

728x90
반응형

댓글