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 函数->