TypeError Traceback (most recent call last) Cell In[87], line 1 ----> 1 a[0,1,2] = 7 TypeError: list indices must be integers or slices, not tuple
时间: 2024-02-14 11:34:10 浏览: 150
Python BeautifulSoup [解决方法] TypeError: list indices must be integers or slices, not str
5星 · 资源好评率100%
这个错误是因为你在尝试给列表a的索引\[0,1,2\]赋值时出现了TypeError。错误提示说列表的索引必须是整数或切片,而不是元组。\[3\]
要解决这个问题,你需要将索引改为整数或切片形式。例如,如果你想给列表a的第0、1、2个元素赋值为7,你可以这样写:a\[0\] = a\[1\] = a\[2\] = 7。这样就可以避免TypeError错误的发生。
#### 引用[.reference_title]
- *1* *2* [【Python报错解决方案】 ValueError Traceback (most recent call last)](https://blog.csdn.net/qq_39885465/article/details/104508452)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [已解决FilegotFoundError Traceback (most recent call last)](https://blog.csdn.net/yuan2019035055/article/details/127835682)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文