기술(Tech, IT)/파이썬(Python)

[Python] subscriptable: TypeError

Daniel803 2022. 9. 28. 13:00

파이썬 코드를 작성하던 중 아래와 같은 에러가 발생했다.

: TypeError: 'int' object is not subscriptable

위 에러는 배열에 존재하지 하지 않는 구역에 접근하려고 할 때 발생하며, 예시는 아래와같다.

 

arr = [1, 2, [3, 4]]
print(arr[0][1])

실행 결과:

TypeError                                 Traceback (most recent call last)
<ipython-input-1-45690f5002b7> in <module>
      1 arr = [1, 2, [3, 4]]
----> 2 print(arr[0][1])

TypeError: 'int' object is not subscriptable

 

* subscript: 아래에 기입한, 아래와 적은 문자[숫자, 기호]

 

참고

- https://en.dict.naver.com/#/entry/enko/a6fa35fb963f4d878f5ec03fe8304648

'기술(Tech, IT) > 파이썬(Python)' 카테고리의 다른 글

[Python] Two-Dimensional Array(2차원 배열)  (0) 2022.10.07
[Python] 문자열 숫자인지 판별  (0) 2022.10.05
[Python] 주석(Annotation)  (0) 2022.09.26
[Python] deque(데크)  (0) 2022.09.25
[Python] for문(for loop)  (0) 2022.09.10