元组的Python类型
我只是想在Python3.85中为元组定义类型。然而,这两种方法似乎都不能正常工作:元组的Python类型,python,typing,Python,Typing,我只是想在Python3.85中为元组定义类型。然而,这两种方法似乎都不能正常工作: 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\t
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
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
结果:
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
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
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
元组(float,str)
结果:
TypeError:元组最多需要1个参数,得到2个
正确的语法是
从键入导入元组
###-----示例------###
元组[浮点,浮点]
元组[float,str]
正确的语法是
从键入导入元组
###-----示例------###
元组[浮点,浮点]
元组[float,str]
输出:
typing.Tuple[float, str]
(3, 'yes', 7.5)
输出:
typing.Tuple[float, str]
(3, 'yes', 7.5)
您的链接清楚地使用了方括号您的链接清楚地使用了方括号谢谢!谢谢你!你能解释一下吗?