python中的类型提示(定义函数时加入箭头->)

原文章:http://t.csdn.cn/K05Sg
偶尔看到一些代码在定义函数时,在def那一行后面会加一个->。
这个玩意儿有个专门的名词叫 type hint, 即类型提示。

官方网站:https://www.python.org/dev/peps/pep-0484/

比如:

def add(a:int, b:int) -> int:
    return a+b

这个表示并没有多么的神奇,意思是:告诉你期待的输入类型和输出类型。上面代码期待的类型为int。

这个网站(https://mypy-lang.org,

猜你喜欢

转载自blog.csdn.net/qq_45583898/article/details/126550395