1.python報錯:TypeError: 'int' object is not subscriptable

b10l07發表於2018-06-28

subscriptable:可以使用下表來訪問資料

  • 此報錯一般是在整數上加了下標
In [20]: a = [("a","b"),("c","d"),"e"]

In [21]: a[2][0]
Out[21]: 'e'

In [22]: a[2][1]
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-22-2e4ed419d949> in <module>()
----> 1 a[2][1]

IndexError: string index out of range

In [23]: a = [("a","b"),("c","d"),3]

In [24]: a[2][0]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-24-adb924ee4885> in <module>()
----> 1 a[2][0]

TypeError: 'int' object is not subscriptable

相關文章