Python中def函数右侧有个->的含义

-> 常常出现在python函数定义的函数名后面,为函数添加元数据,描述函数返回的类型。

: 表示参数的类型建议符


#Python中def函数右侧有个->的含义

def test1(agent: str) -> str:
    print("Annotations:", test1.__annotations__)
    return agent

def test2(agent: str):
    print("Annotations:", test2.__annotations__)
    return agent



if __name__ == '__main__':
    print('hello Test')
    test1('Cat')
    test2('Dog')

 

本文作者:xxxyz

本文链接:https://www.cnblogs.com/xxxyz/p/16524387.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   xxxyz  阅读(714)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起