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')

 

posted @ 2022-07-27 12:00  xxxyz  阅读(788)  评论(0)    收藏  举报