您的位置:首页技术文章
文章详情页

python 函数名之后 有一个箭头 这是什么作用?

浏览:104日期:2022-07-01 09:34:33

问题描述

async def fetch(self, url: str, keys: object, repeat: int) -> (int, object): dosomething() return None

在看别人的程序的时候发现了这样的语句,查了不少地方没找到关于“->”的说明。找到比较相似的是箭头函数,但是样子都不一样。

请问这是什么符号?或者我该去哪里查?

问题解答

回答1:

Function annotations ?'Python 3 provides syntax to attach metadata to the parameters of a function declarationand its return value.'

回答2:

Stackoverflow有了。What does -> mean in Python function definitions?

Python 3 extends the feature by allowing you to attach metadata to functions describing their parameters and return values.

简单的说-> 就是为了告诉用户 具体参数和参数的类型。

详细的可以看:PEP3107https://www.python.org/dev/pe...

回答3:

只是提示该函数 输入参数 和 返回值 的数据类型

方便程序员阅读代码的。

回答4:

http://python3-cookbook.readt...

python cookbook里面有详细描述,建议有空多看看这本书,还是很有帮助的。

回答5:

这个是。。。提示返回值类型的?

回答6:

这个是从python3.5开始就正式纳入的type hint,对于变量的类型进行标注,对于pycharm这样支持的IDE,可以给出更精准的代码提示和变量检查。

具体用法可以看https://docs.python.org/3/lib...

标签: Python 编程
相关文章: