【发布时间】:2021-09-08 03:37:01
【问题描述】:
对不起,我是新手,但我找不到任何方法来解决我的问题。
我正在 3.5.10 版本上开发 Python 应用程序。
def doStuff(self) -> List[MyClass]:
variable1 = MyClass()
myList = list()
myList.append(variable1)
return myList
我希望能够使用 this Python documentation 中提到的别名
我尝试为我的列表创建别名,但它不起作用:
MyAlias = list[MyClass]
我也尝试输入文档中的代码。它也不起作用:
Python 3.5.10 (default, Feb 20 2021, 21:50:32)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> Vector = list[float]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'type' object is not subscriptable
>>>
我是不是做错了什么?
【问题讨论】: