小编kbn*_*bnt的帖子

有没有办法在以前的版本中使用 Python 3.9 类型提示?

在Python 3.9,我们可以使用类型提示中内置的方式小写(而不必输入型特征从typing模块)描述在这里

def greet_all(names: list[str]) -> None:
    for name in names:
        print("Hello", name)
Run Code Online (Sandbox Code Playgroud)

我非常喜欢这个想法,我想知道是否可以使用这种类型提示的方式,但是在以前的 Python 版本中,例如 Python 3.7,我们编写了这样的类型提示:

from typing import List

def greet_all(names: List[str]) -> None:
    for name in names:
        print("Hello", name)
Run Code Online (Sandbox Code Playgroud)

python static-typing type-hinting python-3.9

5
推荐指数
1
解决办法
1409
查看次数

标签 统计

python ×1

python-3.9 ×1

static-typing ×1

type-hinting ×1