python 参数后面加冒号:, 函数后面的添加箭头 None

def test_should_create_bug_report(api_request_context: APIRequestContext) -> None:
def f(text:str,max_len:'int>0'=80) ->str:
    """这个是函数的帮助说明文档,help时会显示"""
    return True
"""
函数声明中,text:str
text 是参数 :冒号后面  str是参数的注释。

如果参数有默认值,还要给注释,如下写。
max_len:'int>0'=80

->str 是函数返回值的注释。

这些注释信息都是函数的元信息,保存在f.__annotations__字典中、

需要注意,python对注释信息和f.__annotations__的一致性,不做检查
不做检查,不做强制,不做验证!什么都不做。
"""
def demo(price: int, number: 33 = 'spam') -> "Nothing to see here":
    print("函数注释", demo.__annotations__)
    print("参数值打印", price, number)
    print(type(price),type(number))

demo("www")

运行结果:

函数注释 {'price': <class 'int'>, 'number': 33, 'return': 'Nothing to see here'}
参数值打印 www spam
<class 'str'> <class 'str'>

 (99条消息) python函数注释,参数后面加冒号:,函数后面的箭头→是什么?_tianv5的博客-CSDN博客_python 函数->

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值