python 函数名之后 有一个箭头 这是什么作用?
问题描述
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...
相关文章:
1. 为什么我ping不通我的docker容器呢???2. debian - docker依赖的aufs-tools源码哪里可以找到啊?3. angular.js - angular内容过长展开收起效果4. dockerfile - 为什么docker容器启动不了?5. docker - 如何修改运行中容器的配置6. angular.js使用$resource服务把数据存入mongodb的问题。7. java - xml 传输数据如何处理更好8. javascript - h5上的手机号默认没有识别9. mac里的docker如何命令行开启呢?10. javascript - 用原生的js获取body和用jquery获取body的的margin值为什么不一样?

网公网安备