Python3 中函数声明的“->”是什么意思?
What does '->' mean with function declaration in Python3?
最近在学习函数声明的时候遇到了Python3中的'->',这是什么意思?到目前为止,除了 Javascript 函数声明之外,我从未见过这样的声明。
def f(self, s: 'str') -> 'bool':
pass
根据 python docs 相关的打字。
This is the python typing feature, which let you specify the return type of functions in python
这是 return 函数值类型的注解。
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.
最近在学习函数声明的时候遇到了Python3中的'->',这是什么意思?到目前为止,除了 Javascript 函数声明之外,我从未见过这样的声明。
def f(self, s: 'str') -> 'bool':
pass
根据 python docs 相关的打字。
This is the python typing feature, which let you specify the return type of functions in python
这是 return 函数值类型的注解。
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.