python - 这个语法在Python中是什么意思? def json_file_to_dict(_file : str) -> dict:?

标签 python python-3.x

def json_file_to_dict(_file: str) -> dict:

这是否意味着函数返回字典类型?据我所知,python 是松散类型语言,它不强制您指定变量的数据类型。

最佳答案

这些是类型提示。它们是作为 PEP 0484 的一部分在 Python 3.5 中引入的。 .

它们本质上是一个契约,该函数返回一个 dict (并期望 _filestr 的实例),但是它们'没有严格执行。它们也是完全可选的。

来自政治公众人物:

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/

相关文章:

python - 在维护目录结构时通过扩展名和复制选择文件时遇到问题

python - 在 Linux 环境中使用子进程运行 shell 命令时,在 python 2.7 中转义连字符

python-3.x - 人脸识别opencv断言失败

python - 判断行的两列是否相等。并创建 bool 列

python - 将代码作为可执行文件运行会出现错误

javascript - Python3将一堆javascript变量从网页抓取到python dict对象中

python - PyAudio - 多 channel 管理\去混音

python - DRF 更改自定义操作的默认 View 集的lookup_field

python - 如何在Python中使用OpenCV检测和绘制轮廓?

python - 在 python 中使用正则表达式返回唯一匹配项