如何在Python中声明数组类型提示?

2024-04-25 19:48:01 发布

您现在位置:Python中文网/ 问答频道 /正文

给定此函数:

def array_returner():
    return ["hello", "there"]

在不导入List(并且使用List[str]语法)的情况下,我如何键入提示这个函数返回一个字符串数组?你知道吗


Tags: 函数字符串hello键入returndef语法情况
2条回答

这就是你要找的:

from typing import List

def array_returner() -> List[str]:
    return ["hello", "there"]

你可以这样做

  • def array_returner() -> [str]:
  • def array_returner() -> List[str]:from typing import List

相关问题 更多 >