def json_file_to_dict(_file: str) -> dict:
这是否意味着函数返回字典类型?据我所知,python 是松散类型语言,它不强制您指定变量的数据类型。
最佳答案
这些是类型提示。它们是作为 PEP 0484 的一部分在 Python 3.5 中引入的。 .
它们本质上是一个契约,该函数返回一个 dict
(并期望 _file
是 str
的实例),但是它们'没有严格执行。它们也是完全可选的。
来自政治公众人物:
While these annotations are available at runtime through the usual
__annotations__
attribute, no type checking happens at runtime. Instead, the proposal assumes the existence of a separate off-line type checker which users can run over their source code voluntarily. Essentially, such a type checker acts as a very powerful linter.
关于python - 这个语法在Python中是什么意思? def json_file_to_dict(_file : str) -> dict:?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32589674/