python-3.x - Python3 中的函数声明 '->' 是什么意思?

标签 python-3.x function arrow-functions function-declaration

最近,我在学习函数声明时在 Python3 中遇到了 '->' 这是什么意思?到目前为止,除了 Javascript 函数声明之外,我从未见过这样的声明。

def f(self, s: 'str') -> 'bool':
    pass

最佳答案

这是函数返回值类型的注释。

def sum() -> expression:

That is, the parameter list can now be followed by a literal -> and a Python expression. Like the annotations for parameters, this expression will be evaluated when the function definition is executed.



https://www.python.org/dev/peps/pep-3107/

关于python-3.x - Python3 中的函数声明 '->' 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54547445/

相关文章:

javascript - ES6 - 使用箭头语法调用匿名生成器

django - 无法在 Ubuntu 14.04、Apache/2.4.7、libapache2-mod-wsgi-py3、Python 3.4 virtualenv、Django 1.86 中获取语言环境编码

json - 如何使用 Python 解析 SQS JSON 消息

python - Windows 上的 Python 3 中的 pyvenv 脚本安装在哪里?

python - 如何验证 tkinter 中的条目?

javascript - ios addEventListener 不工作

javascript - 代码片段以及箭头函数和普通函数的行为

Python BeautifulSoup 在 findall() 中提供字符串时改变行为

python - 如何测试一个函数被调用了多少次

MySQL 游标无法获取数据