Python输入元组

威尔金斯曼

我只是想在python 3.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\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
陆凯文|

正确的语法是

from typing import Tuple

### ---- Examples ----- ###
Tuple[float, float]
Tuple[float, str]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章