gpt4 book ai didi

Python 不可订阅

转载 作者:IT老高 更新时间:2023-10-28 22:24:20 25 4
gpt4 key购买 nike

unsubscriptable 在 TypeError 的上下文中是什么意思,如:

TypeError: 'int' object is unsubscriptable

编辑:导致这种现象的简短代码示例。

a=[[1,2],[5,3],5,[5,6],[2,2]]
for b in a:
print b[0]

> 1
> 5
> TypeError: 'int' object is unsubscriptable

最佳答案

这意味着您尝试将整数视为数组。例如:

a = 1337
b = [1,3,3,7]
print b[0] # prints 1
print a[0] # raises your exception

关于Python 不可订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4123603/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com