我是靠谱客的博主 默默含羞草,最近开发中收集的这篇文章主要介绍python type object is not_python: "TypeError: 'type' object is not subscriptable",觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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"所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部