Python3 中 '->'的含义
在python3中, "->"标记返回函数注释,信息作为.__annotations__属性提供。
__annotations__属性是字典。
键return是用于在箭头后检索值的键。
但是在Python中3.5,PEP 484 - Type Hints附加了一个含义:->用于指示函数返回的类型。它似乎也将在未来版本中强制执行。
比如:
输入
1 def test() -> [1, 2, 3, 4, 5]: 2 pass 3 4 5 print(test.__annotations__)
输出
1 {'return': [1, 2, 3, 4, 5]}
浙公网安备 33010602011771号