概述
Normally Python throws NameError if the variable is not defined:
>>> d[0]
Traceback (most recent call last):
File "", line 1, in
NameError: name 'd' is not defined
However, you've managed to stumble upon a name that already exists in Python.
Because dict is the name of a built-in type in Python you are seeing what appears to be a strange error message, but in reality it is not.
The type of dict is a type. All types are objects in Python. Thus you are actually trying to index into the type object. This is why the error message says that the "'type' object is not subscriptable."
>>> type(dict)
>>> dict[0]
Traceback (most recent call last):
File "", line 1, in
TypeError: 'type' object is not subscriptable
Note that you can blindly assign to the dict name, but
最后
以上就是默默含羞草为你收集整理的python type object is not_python: "TypeError: 'type' object is not subscriptable"的全部内容,希望文章能够帮你解决python type object is not_python: "TypeError: 'type' object is not subscriptable"所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复