Python 不可订阅 [英] Python unsubscriptable

查看:29
本文介绍了Python 不可订阅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

unsubscriptable 在 TypeError 的上下文中意味着什么:

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

TypeError: 'int' object is unsubscriptable

导致这种现象的简短代码示例.

Short code example that results in this phenomena.

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

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

推荐答案

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

It means you tried treating an integer as an array. For example:

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

这篇关于Python 不可订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆