Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中指定参数类型和返回值_Python_Types_Parameters_Return Type - Fatal编程技术网

在Python中指定参数类型和返回值

在Python中指定参数类型和返回值,python,types,parameters,return-type,Python,Types,Parameters,Return Type,我想在函数定义中指定类型,例如: def foo(grid : List[List[str]]) -> int: return 0 但是,当我在解释器(3.7.6)中运行它时,它会声明ModuleNotFoundError:没有名为“List”的模块。是否有文档说明我可以在哪里阅读有关指定参数类型和返回值的更多信息?我将如何实现这一点?它来自模块: 请参见模块中的内容: 看太好了,这正是我想要的谢谢!太好了,这正是我想要的谢谢! from typing import List

我想在函数定义中指定类型,例如:

def foo(grid : List[List[str]]) -> int:
    return 0
但是,当我在解释器(3.7.6)中运行它时,它会声明ModuleNotFoundError:没有名为“List”的模块。是否有文档说明我可以在哪里阅读有关指定参数类型和返回值的更多信息?我将如何实现这一点?

它来自模块:

请参见模块中的内容:


太好了,这正是我想要的谢谢!太好了,这正是我想要的谢谢!
from typing import List


def foo(grid : List[List[str]]) -> int:
    return 0