为啥很少人提 python 3 Function Annotations
答案:1 悬赏:80 手机版
解决时间 2021-02-15 16:23
- 提问者网友:棒棒糖
- 2021-02-14 15:45
为啥很少人提 python 3 Function Annotations
最佳答案
- 五星知识达人网友:纵马山川剑自提
- 2021-02-14 16:03
>>> def f(ham: str, eggs: str = 'eggs') -> str:
... print("Annotations:", f.__annotations__)
... print("Arguments:", ham, eggs)
... return ham + ' and ' + eggs
...
>>> f('spam')
Annotations: {'ham': <class 'str'>, 'return': <class 'str'>, 'eggs': <class 'str'>}
Arguments: spam eggs
'spam and eggs目前就是简单的类型注释而已
... print("Annotations:", f.__annotations__)
... print("Arguments:", ham, eggs)
... return ham + ' and ' + eggs
...
>>> f('spam')
Annotations: {'ham': <class 'str'>, 'return': <class 'str'>, 'eggs': <class 'str'>}
Arguments: spam eggs
'spam and eggs目前就是简单的类型注释而已
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯