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内容请搜索靠谱客的其他文章。
发表评论 取消回复