小编Chr*_*ris的帖子

为什么List不能包含多种类型?

您可以在元组或列表中混合类型.为什么不能在输入提示时指定?

>>> from typing import Tuple, List
>>> t = ('a', 1)
>>> l = ['a', 1]

>>> t2: Tuple[str, int] = ('a', 1)
>>> l2: List[str, int] = ['a', 1]

TypeError: Too many parameters for typing.List; actual 2, expected 1
Run Code Online (Sandbox Code Playgroud)

python type-hinting python-3.x typehints

6
推荐指数
2
解决办法
446
查看次数

标签 统计

python ×1

python-3.x ×1

type-hinting ×1

typehints ×1