最近,我在学习函数声明时在 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/