参考网址:
https://stackoverflow.com/questions/14379753/what-does-mean-in-python-function-definitions
python3中 ->的意义
-
According to this, the example you’ve supplied:
def f(x) -> 123: return x
will be forbidden in the future (and in current versions will be confusing), it would need to be changed to:
def f(x) -> int:
return x
for it to effectively describe that function f returns an object of type int.
-
python中也支持parameter annotations参数注释
Python ignores it. In the following code:def f(x) -> int: return int(x)
the -> int just tells that f() returns an integer. It is called a return annotation, and can be accessed as f.annotations[‘return’].
Python also supports parameter annotations:
def f(x: float) -> int:
return int(x)
: float tells people who read the program (and some third-party libraries/programs, e. g. pylint) that x should be a float. Itis accessed as f.annotations[‘x’], and doesn’t have any meaning by itself. See the documentation for more information: