Python unsubscriptable

前端 未结 4 659
慢半拍i
慢半拍i 2021-01-03 19:12

What does unsubscriptable mean in the context of a TypeError as in:

TypeError: \'int\' object is unsubscriptable

EDIT: Short c

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-03 19:55

    You are trying to lookup an array subscript of an int:

    >>> 1[0]
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: 'int' object is unsubscriptable
    

    That is, square brackets [] are the subscript operator. If you try to apply the subscript operator to an object that does not support it (such as not implementing __getitem__()).

提交回复
热议问题