Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 键入库中的示例代码导致TypeError:';类型';对象不可下标,为什么?_Python_Typing - Fatal编程技术网

Python 键入库中的示例代码导致TypeError:';类型';对象不可下标,为什么?

Python 键入库中的示例代码导致TypeError:';类型';对象不可下标,为什么?,python,typing,Python,Typing,考虑使用Python文档进行键入为什么下面的代码不起作用 >>> Vector = list[float] Traceback (most recent call last): File "<input>", line 1, in <module> TypeError: 'type' object is not subscriptable 我没有发现有关此示例的问题。在3.9中添加了对类型(如list)使用[]运算符进行类型提示

考虑使用Python文档进行
键入
为什么下面的代码不起作用

>>> Vector = list[float]
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: 'type' object is not subscriptable

我没有发现有关此示例的问题。

在3.9中添加了对类型(如
list
)使用
[]
运算符进行类型提示的功能

在早期版本中,它将生成您描述的错误,您需要从
键入导入
列表
对象

from typing import List
List[float]

Python的哪个版本?必须低于3.9此功能在Python 3.9中是新的。如果使用文档顶部的复选框,您可以看到它如何适用于旧版本。投票以不可复制的方式关闭。对,我没有发现我正在阅读3.9的文档,谢谢!
from typing import List
List[float]