What does '->' mean in a function declaration in Python 3?
Question:
Recently, I have come across this ->
in Python 3 when studying function declarations. What does this do and mean? I have never seen such a declaration other than in a Javascript function declaration up until now.
def f(self, s: 'str') -> 'bool':
pass
Answers:
According to python docs related to typings.
This is the python typing feature, which let you specify the return type of functions in python
This is annotation for type of return value of function.
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.
Recently, I have come across this ->
in Python 3 when studying function declarations. What does this do and mean? I have never seen such a declaration other than in a Javascript function declaration up until now.
def f(self, s: 'str') -> 'bool':
pass
According to python docs related to typings.
This is the python typing feature, which let you specify the return type of functions in python
This is annotation for type of return value of function.
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.