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

问题描述 投票:-1回答:2

使用此功能:

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

我将如何键入此函数返回一个字符串数组而不导入List(并使用List[str]语法?)?

python type-hinting
2个回答
0
投票

您可以这样做

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

0
投票

这是您要寻找的:

from typing import List

def array_returner() -> List[str]:
    return ["hello", "there"]
© www.soinside.com 2019 - 2024. All rights reserved.