请教个问题关于报错

‘int’ object does not support item assignment
这种报错信息是什么问题呀

讨论数量: 2
Jason990420

Object is int, no item for assignment.

>>> a = 10
>>> a[2] = 5
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
TypeError: 'int' object does not support item assignment
3年前 评论

错把整型当做列表了,然后对以列表的方式进行赋值了?就是如同下面这样?

In [1]: a = 2

In [2]: a[1] = 3
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-23f2cf2bdf70> in <module>
----> 1 a[1] = 3

TypeError: 'int' object does not support item assignment
3年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!