【发布时间】:2021-02-07 17:22:40
【问题描述】:
我只是想在 python 3.85 中为元组定义类型。但是,documentation 中的两种方法似乎都无法正常工作:
Tuple(float,str)
结果:
Traceback (most recent call last):
File "<ipython-input-30-7964c1934b1f>", line 1, in <module>
Tuple(float,str)
File "C:\Users\kinsm\anaconda3\lib\typing.py", line 727, in __call__
raise TypeError(f"Type {self._name} cannot be instantiated; "
TypeError: Type Tuple cannot be instantiated; use tuple() instead
对比:
tuple(float,str)
结果:
Traceback (most recent call last):
File "<ipython-input-29-fea16b9491a0>", line 1, in <module>
tuple(float,str)
result:
TypeError: tuple expected at most 1 argument, got 2
【问题讨论】:
-
您的链接明显使用了方括号