在 Python 3.9 中,我们可以使用小写内置方式的类型提示(无需从typing
模块中导入类型签名),如下所述:
def greet_all(names: list[str]) -> None:
for name in names:
print("Hello", name)
我非常喜欢这个想法,我想知道是否可以使用这种类型提示的方式,但是在以前的 python 版本中,例如 Python 3.7,我们编写了这样的类型提示:
from typing import List
def greet_all(names: List[str]) -> None:
for name in names:
print("Hello", name)