Nic*_*nas 0 python type-hinting python-3.x python-typing
我正在尝试定义一个列表str作为函数参数的类型,但我不知道如何做到这一点
我知道 python 允许您定义函数来指定函数参数期望的值类型。例子:
def f(param: str):
print(type(param))
Run Code Online (Sandbox Code Playgroud)
但我不知道这个注释是如何调用的param: str,因此很难找到这方面的文档。据我了解,这只是代码文档中的美观,而不是参数的某种类型强制。
您能帮助我定义str该注释的列表和名称吗?
对于我想要的TypeScript的更清晰示例,可以这样写
function func(param: string[]) {}
Run Code Online (Sandbox Code Playgroud)
打字模块为此List目的
from typing import List
def f(param: List[str]):
pass
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7437 次 |
| 最近记录: |