我有以下设置:
from typing import List
a = List[int]
foo(a) == int
我可以使用什么foo
从List
中获取int
?
最佳答案
您可以使用属性__args__
为了取出int
.
from typing import List
a = List[int]
print(a.__args__[0])
结果:<class 'int'>
关于python-3.x - 类型注释: Extract inner type from container type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68202140/