python函数注解

 1 >>> def f(a,b):
 2     return a+b
 3 
 4 >>> f(1,2)
 5 3
 6 >>> f.__annotations__
 7 {}
 8 
 9 >>> def f(a:'第一个变量',b:"The second var")->int:
10     return a+b
11 
12 >>> f.__annotations__
13 {'a': '第一个变量', 'b': 'The second var', 'return': <class 'int'>}
14 >>> f(2,3)
15 5

 

posted @ 2017-11-13 18:50  xiongjiawei  阅读(418)  评论(0)    收藏  举报